GithubHelp home page GithubHelp logo

examples's Introduction

Examples

Sharding database

Scheduled Job

Elastic Job

Quartz

Examples

Quartz Architecture (Single scheduler)

image

Analyze source code.

Create a scheduler

image

Start a scheduler

image

Register JobDetail and Trigger

image

Run QuartzSchedulerThread that is the heart of Quartz

image

image

Quartz Architecture (Cluster mode)

image

Clustering currently only works with JDBC-Jobstore, and each node of the cluster share the same database. Load-balancing occurs automatically, each node of the cluster firing jobs as quickly as it can. When a trigger's firing time occurs, the first node to acquire it with a lock on it. For example, if the job has a repeating trigger every 10 seconds, at 1:00:00 one node runs the job, and at 1:00:10, one node runs the job again, the second node maybe same with first one or not. Fail-over occurs when one of the nodes fails, the other nodes detect the condition and identify the jobs from the database that were in progress within the failed node and fire them.

Failover

image

ClusterManager is responsible for managing the cluster failover. Each instance will send health check to table: SCHEDULER_STATE per specify interval. If one instance doesn't send health check, other instances will acquire the lock:STATE_ACCESS firstly, then recover the failed triggers of failed instance.

Message Middleware

ActiveMQ

Examples

Queue

Queues is straightforward—messages are basically stored in first in, first out order (FIFO). See below figure for a depiction of this. One message is dispatched to ONLY a single consumer at a time. Only when that message has been consumed and acknowledged it can be deleted from the broker’s message store. If one consumer fails to ACK the message, it will be consumed by other consumer. A queue can be consumed by multiple consumers, but one message ONLY can be consumed by one of them.

image

Topic

Topic, one message can be consumed by multiple consumers. For durable subscribers to a topic, a durable subscriber object in the store maintains a pointer to its next stored message and dispatches a copy of it to its consumer as shown in below figure. The message store is implemented in this manner because each durable subscriber could be consuming messages at different rates or they may not all be running at the same time. Also, because every message can potentially have many consumers, a message can’t be deleted from the store until it’s been successfully delivered to every interested durable subscriber.

image

KahaDB

From ActiveMQ5.4, KahaDB is default storage of AMQ. It has three parts: data logs, BTree indexes and cache.

data logs

It is the messages of broker. The Journal consists of a rolling log of messages and commands stored in data files of a certern length.

cache

Itholds messages for fast retrieval in memory after they have bean written to the journal. It will periodically update the reference store with its current message ids and location of the messsages in the journal.

BTree indexes

It ONLY uses one index file for all its destinations. All index file updates also recorded in a redo log. This ensures that the indexes can be brought back in a consistent state.

image

The directory structure of KahaDB

image

  • db-x.log It stores the journal data files.
  • db.data It is BTree indexes, records all the indexes of desctinations.
  • db.redo All index file updates are also recorded in the redo log. This ensures that the indexes can be brought back in a consistent state when broker is shutdown uncleanly.
  • lock It ensures ONLY one broker can access the data at give anytime, it used in hot stand-by status where there are more than one broker with same name.

Consumer

Consumer code mainly has three parts: read message via transport, the memory queue to store pooled messages and dispatcher to dispatch message to consumers which consums the messages. The queue and topic consumers are same process flow.

image

EventBus

Distributed lock

examples's People

Contributors

andy-gong avatar dependabot[bot] avatar

Stargazers

Jung Wei Li avatar Wang Rui avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.