Your SlideShare is downloading. ×
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Jms слайды
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Jms слайды

251

Published on

jms intro

jms intro

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

  • Be the first to like this

No Downloads
Views
Total Views
251
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. JMSjava messaging service bolkimen@yahoo.com
  • 2. General conceptsProducer/Publisher Consumer/Subscriber QueueTopic Message > JMS Message > provider ... ...
  • 3. Queues Producer Consumer Queue
  • 4. Topics Producer Topic Consumer
  • 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. 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. Synchronous messagingwhile(true) { Message message = consumer.receive(); ....}
  • 8. Asynchronous messaging(listener class)class AsyncConsumerMessageListener implements MessageListener { public void onMessage(Message message) { TextMessage msg = (TextMessage) message; .... }}
  • 9. Asynchronous messaging(listener class usage)AsyncConsumerMessageListener asyncConsumer = new AsyncConsumerMessageListener();MessageConsumer consumer = session.createConsumer(destination);consumer.setMessageListener(asyncConsumer);
  • 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. SpringjmsQueueConnectionFactory<bean id="jmsQueueConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory"> <property name="targetConnectionFactory" ref="amqConnectionFactory" /></bean>
  • 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. SpringjmsTemplate<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> <constructor-arg ref="jmsQueueConnectionFactory" /></bean>
  • 14. Springmessage listener@Componentpublic class WebConsumer implements MessageListener{ public void onMessage( final Message message ) {…}}
  • 15. Springproducer@Componentpublic class WebProducer{ @Autowired private JmsTemplate jmsTemplate; public void send(String message) throws JMSException { jmsTemplate.convertAndSend("TESTQUEUE", message); }}
  • 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

×