Jms слайды

388 views
340 views

Published on

jms intro

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
388
On SlideShare
0
From Embeds
0
Number of Embeds
19
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×