转自github
===== #demo project is how to use the base APIs.
======
This project provides some examples of using Spring JMS for both asynchronous and synchronous message consumption.
All of the examples for asynchronous message consumption utilize the Spring DefaultMessageListenerContainer for message consumption.
Spring JMS supports three types of message listeners including:
- javax.jms.MessageListener
- SessionAwareMessageListener
- [MessageListenerAdapter](http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/jms/listener/adapter/MessageListenerAdapter.html
These three types of message listeners are all demonstrated using examples in the async directory.
These examples are intended to be run from the command-line using Maven. The consumer should be run in one terminal and the producer should be run in a separate terminal. Below are examples of running each of the three asynchronous examples.
$ cd ./async/message-listener
$ mvn -Pproducer exec:java
$ cd ./async/message-listener
$ mvn -Pconsumer exec:java
$ cd ./async/session-aware-message-listener
$ mvn -Pproducer exec:java
$ cd ./async/session-aware-message-listener
$ mvn -Pconsumer exec:java
This example requires a couple of arguments, the first one for the destination name and the second one for the message type. The destination name should be either FOO.TEST or FOO.TEST2. The message type should text, bytes, map or object. Below is an example of text:
$ cd ./async/message-listener-adapter
$ mvn -Pproducer exec:java -Dexec.args="FOO.TEST2 text"
These arguments allow you to invoke one of two MessageListenerAdapter
examples and to send four different types of messages.
$ cd ./async/message-listener-adapter
$ mvn -Pconsumer exec:java
The example for synchronous message consumption uses the Spring JmsTemplate.
This example is also intended to be run from the command-line using Maven. The consumer should be run in one terminal and the producer should be run in a separate terminal. Below is an example of running the synchronous example.
$ cd ./sync/jms-template
$ mvn -Pconsumer exec:java -DreceiveType=receiveAndConvert
This example supports two different types of sends including a simple convertAndSend and also a jmsSend. These two types are specified using an argument when starting up the producer as shown below:
$ cd ./sync/jms-template
$ mvn -Pproducer exec:java -DsendType=convertAndSend