Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
JMSjava messaging    service       bolkimen@yahoo.com
General conceptsProducer/Publisher                                     Consumer/Subscriber                             Que...
Queues Producer           Consumer            Queue
Topics  Producer   Topic   Consumer
Message typesJMS specification provides standard implementations of javax.jms.Message:1.   javax.jms.BytesMessage - array ...
The working algorithm with JMS1.   Obtain a javax.jms.ConnectionFactory using a JNDI lookup. (The default ConnectionFactor...
Synchronous messagingwhile(true) {      Message message = consumer.receive();      ....}
Asynchronous messaging(listener class)class AsyncConsumerMessageListener implements MessageListener {      public void onM...
Asynchronous messaging(listener class usage)AsyncConsumerMessageListener asyncConsumer = new AsyncConsumerMessageListener(...
SpringamqConnectionFactory<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">      <pro...
SpringjmsQueueConnectionFactory<bean id="jmsQueueConnectionFactory"   class="org.springframework.jms.connection.SingleConn...
Springlistener-container<jms:listener-container      connection-factory="jmsQueueConnectionFactory"      destination-type=...
SpringjmsTemplate<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">          <constructor-arg ref="j...
Springmessage listener@Componentpublic class WebConsumer implements MessageListener{  public void onMessage( final Message...
Springproducer@Componentpublic class WebProducer{      @Autowired      private JmsTemplate jmsTemplate;     public void se...
Sources & useful links1.   Official JMS tutorial book2.   http://www.thirdeyeconsulting.com/indyjug/jms/jms.html3.   http:...
Upcoming SlideShare
Loading in …5
×

Jms слайды

497 views

Published on

jms intro

  • Be the first to comment

  • Be the first to like this

Jms слайды

  1. 1. JMSjava messaging service bolkimen@yahoo.com
  2. 2. General conceptsProducer/Publisher Consumer/Subscriber QueueTopic Message > JMS Message > provider ... ...
  3. 3. Queues Producer Consumer Queue
  4. 4. Topics Producer Topic Consumer
  5. 5. Message typesJMS specification provides standard implementations of javax.jms.Message:1. javax.jms.BytesMessage - array of bytes2. javax.jms.MapMessage - key-value pairs3. javax.jms.ObjectMessage - serialized Java object4. javax.jms.StreamMessage - stream of Java primitive values5. javax.jms.TextMessage - Java String object (used for XML)
  6. 6. The working algorithm with JMS1. Obtain a javax.jms.ConnectionFactory using a JNDI lookup. (The default ConnectionFactory names are different depending on the JMS provider.)2. Obtain a javax.jms.Connection from the ConnectionFactory.3. Obtain a javax.jms.Session from the Connection.4. Create a javax.jms.MessageProducer or javax.jms.MessageConsumer from the Session.5. For a MessageProducer, send the message, or for a MessageConsumer, receive the message (synchronous) or set the message listener (asynchronous).6. Start the Connection to start message delivery.7. Ultimately close the Connection.
  7. 7. Synchronous messagingwhile(true) { Message message = consumer.receive(); ....}
  8. 8. Asynchronous messaging(listener class)class AsyncConsumerMessageListener implements MessageListener { public void onMessage(Message message) { TextMessage msg = (TextMessage) message; .... }}
  9. 9. Asynchronous messaging(listener class usage)AsyncConsumerMessageListener asyncConsumer = new AsyncConsumerMessageListener();MessageConsumer consumer = session.createConsumer(destination);consumer.setMessageListener(asyncConsumer);
  10. 10. SpringamqConnectionFactory<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="${jms.url}" /></bean>1) jms.url=tcp://localhost:616162) jms.url=vm://localhost
  11. 11. SpringjmsQueueConnectionFactory<bean id="jmsQueueConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory"> <property name="targetConnectionFactory" ref="amqConnectionFactory" /></bean>
  12. 12. Springlistener-container<jms:listener-container connection-factory="jmsQueueConnectionFactory" destination-type="queue" container-type="default"> <jms:listener destination="TESTQUEUE" ref="webConsumer" method="onMessage" /></jms:listener-container>
  13. 13. SpringjmsTemplate<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <constructor-arg ref="jmsQueueConnectionFactory" /></bean>
  14. 14. Springmessage listener@Componentpublic class WebConsumer implements MessageListener{ public void onMessage( final Message message ) {…}}
  15. 15. Springproducer@Componentpublic class WebProducer{ @Autowired private JmsTemplate jmsTemplate; public void send(String message) throws JMSException { jmsTemplate.convertAndSend("TESTQUEUE", message); }}
  16. 16. Sources & useful links1. Official JMS tutorial book2. http://www.thirdeyeconsulting.com/indyjug/jms/jms.html3. http://www2.sys-con.com/itsg/virtualcd/Java/archives/0604/chappell/index.html

×