ENTERPRISEMESSAGING ANDJBOSS A-MQ
Jakub Knetl
1.1
Messaging systems
JMS specificationJMS API
JBoss A-MQ
JBoss A-MQ and Apache ActiveMQProtocolstopologies
Apache Artemis
LECTURE OUTLINE
1.2
Method for asynchronous message (data) transfer between different systems which allowsto integrate these systems.
WHAT IS ENTERPRISE MESSAGING
1.3
Method for asynchronous message (data) transfer between different systems which allowsto integrate these systems.
WHAT IS ENTERPRISE MESSAGING
1.4
data exchange between applicationsMessage oriented middleware (MoM)
Message broker servers as mediator between communicating parties
ENTERPRISE MESSAGINGARCHITECTURE
1.5
Other methods:
Webservices (REST, SOAP)JDBC and ORMRMICORBA...
WHY DO WE NEED ANOTHERCOMMUNICATION METHOD?
1.6
BENEFITS OF MESSAGING SYSTEMAsynchronous communicationLoose couplingScalabilityReliabilityMessage routing and transformation
1.7
Web music streaming service, which allows to upload and store your own music files. Musicfiles are stored in the ogg format in some shared storage (NAS, cloud, whatever, ...).However it allows to upload music in many formats (mp3, flac, wav, aac, and others) whichare converted by the service into ogg.
Where will we convert data?
EXAMPLE USE CASE
1.8
Web music streaming service, which allows to upload and store your own music files. Musicfiles are stored in the ogg format in some shared storage (NAS, cloud, whatever, ...).However it allows to upload music in many formats (mp3, flac, wav, aac, and others) whichare converted by the service into ogg.
Where will we convert data?
server side?client side?
Usually none of them because of required CPU performance...
EXAMPLE USE CASE
1.9
Benefits
asynchronous communication - server doesn't need to wait neither until data areencoded or sentloose coupling - server doesn't need to know anything about the encoderscalability - we may just start new processes as encodersmessage routing and transformation - message may be arbitrary routed betweenusing metadata information
1 server will just simply store data into temporary place shared storage
2 It will sends message containing metadata about music file into a queue
3 There may be arbitrary numbers of running consumer, which will perform encodingand upload into final storage location in ogg format.
EXAMPLE USE CASE - SOLUTION
1.10
JMS SPECIFICATIONgoal is to:
provide messaging functionality to the java applicationsmaximizes portability between messaging productsdefine common messaging concepts
JMS provides API for messaging productsJMS is not messaging system!JMS does not address:
load balancingfault toleranceadministrationwire protocolsecurity
1.11
BASIC TERMSJMS providerJMS client
producer/consumer
non JMS clientJMS destinantionJMS domainsJMS Message
1.12
MESSAGE STRUCTUREHeaders
metadata about messagestored as key value pairstwo types (differs only semantically):
headers (same for all messages)properties
arbitrary key-values (some of them arestandardized)
Payload
may contain different types of payload
JMS MessageJMS Headers
JMS Properties
JMS payload
1.13
MESSAGE HEADERS LISTHeader name meaning
JMSDestination destination on the broker
JMSDeliveryMode persistent or nonperistent delivery mode
JMSExpiration message will not be delivered after expiration
JMSMessageID Identifiaction of the message
JMSPriority Number 0 - 9 (0-4 low, 5-9 high priority). Advise only
JMSTimestamp Time when the message is handed to provider for send
JMSCorrelationID links message to another one
JMSReplyTo Destination for reply
JMSRedelivered Contains true if the message was likely redelivered
1.14
PREDIFINED PROPERTIES
Search through JMS specification!
1.15
MESSAGE SELECTORSMessage filtering based on properties and headersCondition based on subset of SQL92
FLIGHT_NUMBER LIKE 'N14%'
PRICE
MESSAGE CONTENTThere are several types of message defined in JMS:
TextMessage - String contentMapMessage - "body contains a set of name-value pairswhere names are Strings and values are Java primitive type"BytesMessage - stream of uninterpreted bytes bytesStreamMessage - stream of java primitive values (read and filled sequentially)ObjectMessage - Serializable object
1.17
COMMUNICATION DOMAINSCommunication type:
Point-to-point (PTP)Publish/Subscribe (Pub/Sub)
1.18
POINT TO POINT COMMUNICATIONDestination is a queueone of multiple consumers gets messageLoad is distributed across consumersMessage is stored until some consumers receives it
1.19
PUBLISH SUBSCRIBE DOMAINDestination is a topicmessage is delivered to all subscribersmessage is thrown away if there is no subscriptionDurable subscriber
if durable subscriber disconnects broker is obliged to store all messages for laterdelivery
1.20
IT IS TIME FOR HISTORY...
1.21
JMS APIJMS 1.0 (2001)
Different APIs for pub/sub and PTP communication
JMS 1.1 (2002)
Classic API - unified API for pub/sub and PTP
JMS 2.0 (2013)
Classic API
it is not deprecated and will remain part of JMS indefinitely
Simplified API
less code neededAutoCloseable resources -> Java 7 neededno checked exceptions
1.22
CLASSES OF CLASSIC APIConnectionFactoryConnection - heavyweight object (allocates resources outside JVM)Session - lightweight object
factory for MessageProducer, MessageConsumer and Destinationshould not be shared between threadsdefines serial order and transaction context
MessageProducer
for producing messages
MessageConsumer
for consuming messages
Destination - administered objectMessage
1.23
RELIABILITY OF MESSAGEdelivery modeacknowledgement modetransactional mode
1.24
DELIVERY MODEdetermines level of delivery reliability
Persistent (default)
provider should persist the messagemessage must be delivered once and only once even in case of provider failure
Nonpersistent
provider is instructed not ot presist the messagemessage must be delivered at most oncemessage is usually lost on provider failurebetter performance
1.25
MESSAGE ACKNOWLEDGEMENTDelivery between broker and client is not considered successful until message isacknowledged.acknowledgement modes:
AUTO_ACKNOWLEDGEDUPS_OK_ACKNOWLEDGECLIENT_ACKNOWLEDGE
1.26
TRANSACTIONSSession can be transactedmultiple messages handled as atomic unittransaction is completed by calling commit() or rollback() on sessioncommit also acknowledges messageSupport for distributed transaction is not required by JMS
but still many providers implement distributed transactionsJMS recommends support using JTA XAResource API
1.27
CODE EXAMPLES
1.28
PART IIAPACHE ACTIVEMQ
1.29
APACHE ACTIVEMQOpensource MoMJMS 1.1 compliantSupports many protocols and clientsother features:
High availabilityscalibilitymanagementsecurity
1.30
JBOSS A-MQOpen-source messaging platformMessaging system based on Apache ActiveMQRuns on OSGI containerEnable easy deploymentProvides web based management console
1.31
JBOSS A-MQ
1.32
CONFIGURATIONXML filemost of things work out of the box configuration example
1.33
http://activemq.apache.org/xml-configuration.html
MESSAGE STORESkahaDBmulti kahaDBlevelDBJDBC
1.34
CONNECTION TO BROKERTransport connectors
For client to broker connections
Network connectors
For broker to broker connections
Many transport protocols supported:
tcp, udp, nio, ssl, http/https, vm
1.35
WIRE PROTOCOLSOpenwireSTOMPAMQPMQTT
1.36
PROTOCOL URISdetermines what:
protocol will be usedlocation of the broker (typically hostname and port)
high level uris:
typically uses composite URIfailoverfabric
failover:(tcp://primary:61616,tcp://secondary:61616)?randomize=false
1.37
RUNTIME MANAGEMENTThere are three options for management:
web consoleJMXKaraf OSGi console
DEMO!
1.38
HIGH AVAILABILITY (HA)Messaging systems usually processes business critical databroker must be accessible 24/7ActiveMQ provides various mechanisms to ensure HA
1.39
HA IN ACTIVEMQGroup of brokers forms logically one brokerMaster broker
communicates with clients
Slave brokers
Passive (all connectors are stopped)
election mechanismsclient reconnects in case of failure (failover)Message acknowledgment after the message is stored safely
1.40
MASTER SLAVE FOR HAShared JDBC master/slaveShared file system master/slaveReplicated levelDB master/slave
1.41
SCALABILITY: NETWORK OF BROKERSconnections between brokermessage forwardingenables massive scalabilityrequires careful configuration
1.42
NETWORK CONNECTOR
Broker A :
1.43
NETWORK OF BROKERSduplex connectionsdestination filteringdynamic vs static forwardingAdvisoryMessagesnetwork consumer prioritynetworkTTL
1.44
HIERARCHIES OF NETWORKSconcentrator topologyhub and spokes topologytree topologymesh topologycomplete graph
1.45
OTHER ACTIVEMQ FEATURESexclusive consumersmessage groupscomposite destinationswildcards (. * >)virtual destinations
See http://activemq.apache.org/features.html
1.46
http://activemq.apache.org/features.html
APACHE ACTIVEMQ ARTEMISnew Apache MoMnon-blocking architecture => great performancemerges codebase with JBoss HornetQJMS 2.0 compliantSupport for:
ActiveMQ clientsAMQPSTOMPHornetQ clients
More details on .Artemis website
1.47
https://activemq.apache.org/artemis/
THANK YOU!
1.48