Introduction to ActiveMQ - PowerPoint PPT Presentation

introduction to activemq n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to ActiveMQ PowerPoint Presentation
Download Presentation
Introduction to ActiveMQ

play fullscreen
1 / 33
Introduction to ActiveMQ
1143 Views
Download Presentation
federico
Download Presentation

Introduction to ActiveMQ

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. IntroductiontoActiveMQ Prepared for the Austin Java Users Group by Gerald Cantor

  2. Introduction • ActiveMQ and Messaging • ActiveMQ Components • Basic Administration • Enterprise Features of ActiveMQ • Camels and Mules • Questions and Answers Agenda

  3. Most popular open source message broker • 100% Java Implementation • Available for download at http://activemq.apache.org • Windows and Unix/Linux distributions available • Numerous connection protocols • Wide range of language clients • Can be run stand alone or embedded in JEE container • Full support of JMS 1.1 specification • Full support of J2EE 1.4 specification • Simple browser based administration • Advancedfeatures • Three simple steps to get going • Download • Extract (.zip or .tgz) • Startup(.bat or .sh) Introduction

  4. Recommended Reading Introduction Recommended Web Sites • http://activemq.apache.org • http://fusesource.com/resources/video-archived-webinars/ • http://www.slideshare.net/search/slideshow?searchfrom=header&q=activemq

  5. Point to Point Messaging Queue Producer Consumer ActiveMQ and Messaging Publish Subscribe Messaging Subscriber Topic Publisher Subscriber Subscriber

  6. Simple Consumer public class SimpleConsumer { private static final Log LOG = LogFactory.getLog(SimpleConsumer.class); private static final Boolean NON_TRANSACTED = false; private static final String CONNECTION_FACTORY_NAME = "myJmsFactory"; private static final String DESTINATION_NAME = "queue/simple"; private static final intMESSAGE_TIMEOUT_MILLISECONDS = 120000; public static void main(String args[]) { Connection connection = null; try { // JNDI lookup of JMS Connection Factory and JMS Destination Context context = new InitialContext(); ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME); Destination destination = (Destination) context.lookup(DESTINATION_NAME); connection = factory.createConnection(); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(destination); LOG.info("Start consuming messages from " + destination.toString() + " with " + MESSAGE_TIMEOUT_MILLISECONDS + "ms timeout"); // Synchronous message consumer inti = 1; while (true) { Message message = consumer.receive(MESSAGE_TIMEOUT_MILLISECONDS); if (message != null) { if (message instanceofTextMessage) { String text = ((TextMessage) message).getText(); LOG.info("Got " + (i++) + ". message: " + text); } } else { break; } } . . . ActiveMQ and Messaging

  7. Simple Producer public class SimpleProducer { private static final Log LOG = LogFactory.getLog(SimpleProducer.class); private static final Boolean NON_TRANSACTED = false; private static final long MESSAGE_TIME_TO_LIVE_MILLISECONDS = 0; private static final intMESSAGE_DELAY_MILLISECONDS = 100; private static final intNUM_MESSAGES_TO_BE_SENT = 1000; private static final String CONNECTION_FACTORY_NAME = "myJmsFactory"; private static final String DESTINATION_NAME = "queue/simple"; public static void main(String args[]) { Connection connection = null; try { // JNDI lookup of JMS Connection Factory and JMS Destination Context context = new InitialContext(); ConnectionFactory factory = (ConnectionFactory) context.lookup(CONNECTION_FACTORY_NAME); Destination destination = (Destination) context.lookup(DESTINATION_NAME); connection = factory.createConnection(); connection.start(); Session session = connection.createSession(NON_TRANSACTED, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); producer.setTimeToLive(MESSAGE_TIME_TO_LIVE_MILLISECONDS); for (inti = 1; i <= NUM_MESSAGES_TO_BE_SENT; i++) { TextMessagemessage = session.createTextMessage(i + ". message sent"); LOG.info("Sending to destination: " + destination.toString() + " this text: '" + message.getText()); producer.send(message); Thread.sleep(MESSAGE_DELAY_MILLISECONDS); } . . . ActiveMQ and Messaging

  8. Consume from multiple destinations via wildcards • ActiveMQ destinations follow a hierarchical naming convention • usergroups.java.austin • usergroups.java.miami • usergroups.ruby.austin • meetup.marketing.austin • Three special characters using in naming ActiveMQ destinations • . Used to separate elements in a destination name • * Used to match one element • > Used to match one or all trailing elements ActiveMQ and Messaging

  9. Consume from multiple destinations via wildcards • usergroups.java.austin ActiveMQ and Messaging • usergroups.java.miami Consumer • usergroups.java.* • usergroups.ruby.austin • meetup.marketing.austin

  10. Consume from multiple destinations via wildcards • usergroups.java.austin ActiveMQ and Messaging • usergroups.java.miami Consumer • usergroups.> • usergroups.ruby.austin • meetup.marketing.austin

  11. Consume from multiple destinations via wildcards • usergroups.java.austin ActiveMQ and Messaging • usergroups.java.miami Consumer • *.*.austin • usergroups.ruby.austin • meetup.marketing.austin

  12. Send to multiple destinations via composite destinations • usergroups.java.austin ActiveMQ and Messaging • usergroups.java.miami Producer • usergroups.java.austin, • meetup.marketing.austin • usergroups.ruby.austin • meetup.marketing.austin • Composite destinations include • queues and topics or a mix of both

  13. Send to multiple destinations via composite destinations • usergroups.java.austin ActiveMQ and Messaging • usergroups.java.miami • usergroups.java.austin, • usergroups.ruby.austin, • meetup.marketing.austin Producer • usergroups.ruby.austin • meetup.marketing.austin

  14. Transport Connectors • Used for client to broker connectivity • Variety of protocols • URI format • Network Connectors • Used for broker to broker connectivity • Variety of protocols • URI format • Message Store • Used for message persistence • Used for internal ActiveMQ bookkeeping • Variety of backing stores • Security Plug-ins • Authentication • Authorization • Certificate-based ActiveMQ Components

  15. Transport Connectors • tcp://activemq.gcantor.com:61616?trace=true • vm://localhost?brokerConfig=xbean:activemq.xml • static:(tcp://activemq.gcantor.com:61616,tcp://activemq.tcantor.com:61616) ActiveMQ Components

  16. Transport Configuration – single or multiple . . . <transportConnectors> <transportConnector name="tcp“ uri="tcp://localhost:61616?trace=true"/> </transportConnectors> . . . ActiveMQ Components . . . <transportConnectors> <transportConnector name="tcp“ uri="tcp://localhost:61616?trace=true"/> <transportConnector name=“nio“ uri=“nio:localhost:61618?trace=true"/> </transportConnectors> . . .

  17. Network Connectors ActiveMQ Components

  18. Network Connector Configuration . . . <networkConnectors> <networkConnector uri="static:(tcp://localhost:61616)“ duplex="true"> </networkConnector> </networkConnectors> . . . ActiveMQ Components . . . <networkConnectors> <networkConnectoruri="multicast://default“ dynamicOnly="true" networkTTL="3" prefetchSize="1" decreaseNetworkConsumerPriority="true" /> </networkConnectors> . . . <transportConnectors> <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" discoveryUri="multicast://default" /> </transportConnectors>

  19. Message Store • KahaDB • File based, transactional store • Optimized for storing messages • Recommended message store • AMQ Message Store • File based, transactional store • Optimized for throughput • Not a good choice when using thousands of queues • JDBC Message Store • Messages stored in relational database • Many driver options • Useful for when database is already part of infrastructure • Memory Message Store • Messages stored in memory • Very, very fast • Does not survive broker shutdown or crashes ActiveMQ Components

  20. Message Store Configuration – simple / complex . . . <persistenceAdapter> <kahaDB directory="${activemq.base}/data/kahadb"/> </persistenceAdapter> . . . ActiveMQ Components . . . <persistenceAdapter> <amqPersistenceAdapter directory=“target/Broker2-data/activemq-data” syncOnWrite=“true” indexPageSize=“16kb” indexMaxBinSize=“100” maxFileLength=“10mb” /> </persistenceAdapter> . . .

  21. Security Plug-ins • Authentication • Simple • handles credentials directly in XML configuration or via properties file • requires extra level of security to protect credentials • JAAS • implements the Java Authentication and Authorization Service API • providing more full featured and flexible authentication • can be used to leverage certificate-based authentication ActiveMQ Components

  22. Security Plug-ins • Authorization • Destination level • supports 3 levels of access: read/write/admin • fairly easy to use, but coarse grained • Can be combined with certificate-based authentication • Message level • very granular but is a purely programmatic approach • you have full control • Complete custom security via plug-in architecture • Driver’s choice • Most complex approach, but you can get exactly what you want • Combination of programming and proper configuration setup ActiveMQ Components

  23. Simple Browser-based administration • CRUD Operations on queues / topics • Simple message send • Simple durable subscribers management • Basic views of connections, network configurations • Basic reporting via simple graphs ActiveMQ Administration

  24. Queue View ActiveMQ Administration

  25. JMX Administration • Fully exposed management via JMX API • Accessible via JMX GUI client, such as jconsole • Accessible via JMX programmatic API • Ability to gather very detailed information • Broker statistics • Queue / Topic attributes • In-flight transactions • Important performance indicators • More extensive operations • CRUD-based operations • Specialized operations ActiveMQ Administration

  26. jconsole view ActiveMQ Administration

  27. Fail Over Configuration • Shared Nothing Master / Slave • Master broker and slave broker have independent message stores • Master will replicate information to slave, prior to deeming message process “done” • If master dies, slave can either shutdown or become new master • Simple configuration but incurs extra overhead • Master can have only 1 slave • Manual intervention necessary when master dies • manually making slave master or adding a new slave • Shared Master / Slave • Master broker and slave broker share a message store • No limit to number of slave brokers • Brokers compete for message store lock • Distributed file lock semantics required (e.g. SAN, NFS4) • When master dies, the first slave that obtains the lock becomes the new master ActiveMQ Enterprise Features

  28. Network of Brokers • Brokers can be configured to form network topologies • Messages are stored and forwarded across the broker networks • Allows for horizontal scaling • Care needs to be used when defining networks • Two aspects to networking brokers • What’s passed between brokers • How the networks are formed • A broker’s active and durable consumer destinations are shared • Info can be filtered • Choice of unidirectional message exchange or duplex exchange • Networks can be static or dynamic • Dynamic networks require advisory support enabled • Some limitation with dynamic broker discovery ActiveMQ Enterprise Features

  29. Fault Tolerant Broker Network • Combines the techniques of master / slave brokers and network of brokers • Host 2 • Host 4 • Host 1 • Host 3 ActiveMQ Enterprise Features Master A1 Slave A2 Master C1 Slave C2 Slave B2 Master B1 Slave D2 Master D1 • failover://(tcp://brokerA,tcp://brokerB,tcp://brokerC,tpc://brokerD)?randomize=true Producer

  30. Enterprise Integration Pattern Frameworks • Enterprise Integration Patterns build heavily on messaging • Apache Camel and MuleSoft Mule ESB are comprehensive EIP frameworks • Each provides solid implementations of key EIPs • Wire Tap • Recipient List • Content Based Router • Simple and complex messaging integrations can often be reduced to a few lines of DSL • Robust messaging routing ActiveMQ Camels and Mules !?!?

  31. References ActiveMQ Camels and Mules !?!?

  32. Camel Example Consume messages from queue://test.camel-queue and write to a file under test directory Take files under test directory and publish to topic://test.camel-topic ActiveMQ Camels and Mules !?!? <!-- lets configure the ActiveMQ JMS broker server to listen on TCP 61616 --> <broker:broker id="broker" useJmx="false" persistent="false" brokerName="localhost"> <broker:transportConnectors> <broker:transportConnector name="tcp" uri="tcp://localhost:61616"/> </broker:transportConnectors> </broker:broker> <!-- lets configure the Camel ActiveMQ to use the ActiveMQ broker declared above --> <bean id="test-jms" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="brokerURL" value="tcp://localhost:61616"/> </bean> <camel:camelContext id="camelContext"> <camel:route> <camel:fromuri="test-jms:queue:test.camel-queue" /> <camel:touri="file://test" /> </camel:route> <camel:route> <camel:fromuri="file://test" /> <camel:touri="test-jms:topic:test.camel-topic" /> </camel:route> </camel:camelContext> </beans>

  33. IntroductiontoActiveMQ Prepared for the Austin Java Users Group by Gerald Cantor