Giter Club home page Giter Club logo

spring-jms-examples's Introduction

Spring JMS Examples

This project provides some examples of using Spring JMS for both asynchronous and synchronous message consumption.

Asynchronous 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:

These three types of message listeners are all demonstrated using examples in the async directory.

Running the Examples

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.

Run the Producer for the MessageListener Example

$ cd ./async/message-listener-adapter
$ mvn -Pproducer exec:java

Run the Consumer for the MessageListener Example

$ cd ./async/message-listener-adapter
$ mvn -Pconsumer exec:java

Run the Producer for the SessionAwareMessageListener Example

$ cd ./async/message-listener-adapter
$ mvn -Pproducer exec:java

Run the Consumer for the SessionAwareMessageListener Example

$ cd ./async/message-listener-adapter
$ mvn -Pconsumer exec:java

Run the Producer for the MessageListenerAdapter Example

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.

Run the Consumer for the MessageListenerAdapter Example

$ cd ./async/message-listener-adapter
$ mvn -Pconsumer exec:java

Synchronous Consumption

The example for synchronous message consumption uses the Spring JmsTemplate.

Running the Examples

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.

Run the Consumer for the JmsTemplate Example

$ cd ./sync/jms-template
$ mvn -Pconsumer exec:java 

Run the Producer for the JmsTemplate Example

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

Summary

If you have any questions about these examples, please create an issue for the project. This will allow everyone to see all questions and answers and it will notify me when folks enter new issues.

I also blog about JMS occasionally. Here are some popular posts I have written about Spring JMS:

spring-jms-examples's People

Contributors

bsnyder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-jms-examples's Issues

Problem With pom.xml

Hey Bruce,

I get the following error when trying to build the project at the spring-jms-example root and also when building from the command line as indicated in the readme:

Could not find artifact org.bsnyder.spring.jms:spring-jms-activemq:pom:1.0-SNAPSHOT

I'm sure it's something simple but wanted to post for a quick answer in case others might run into the same problem. I've been reading your blogs and think it's some of the best Spring JMS info on the web so just wanted to get your code examples running.

Build works but producer execution not

the

mvn clean install 

works great, but when I type

mvn -Pproducer exec:java

get the error

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Spring JMS Examples
[INFO] Async :: MessageListener Example
[INFO] Async :: MessageListenerAdapter Example
[INFO] Async :: SessionAwareMessageListener Example
[INFO] Sync :: JmsTemplate Example
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring JMS Examples 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> exec-maven-plugin:1.2:java (default-cli) > validate @ spring-jms-examples >>>
[INFO] 
[INFO] <<< exec-maven-plugin:1.2:java (default-cli) < validate @ spring-jms-examples <<<
[INFO] 
[INFO] --- exec-maven-plugin:1.2:java (default-cli) @ spring-jms-examples ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Spring JMS Examples ................................ FAILURE [  0.347 s]
[INFO] Async :: MessageListener Example ................... SKIPPED
[INFO] Async :: MessageListenerAdapter Example ............ SKIPPED
[INFO] Async :: SessionAwareMessageListener Example ....... SKIPPED
[INFO] Sync :: JmsTemplate Example ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.899 s
[INFO] Finished at: 2016-05-10T22:48:47-03:00
[INFO] Final Memory: 8M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli) on project spring-jms-examples: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2:java are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException

mvn command wrong

mvn -Pproducer exec:java -DsendType=converAndSend
should be
mvn -Pproducer exec:java -DsendType=convertAndSend
There is a ‘t’ end the word ‘convent’.

destination names don't match between readme and consumer in message-listener-adapter

README suggests to run by command:

Run the Producer for the MessageListenerAdapter Example

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
$ mvn -Pproducer exec:java -Dexec.args="FOO.TEST2 text"

but the actually destination defined in consumer xml are

<jms:listener destination="TEST.FOO" ref="messageDelegate" />
<jms:listener destination="TEST.FOO2" ref="messageDelegate" />

PS: the cd above is also incorrect .
shall be $ cd ./async/message-listener-adapter

none of mvn command works

I have seen none of mvn command works.

C:\servers\spring-jms-examples-master\sync\jms-template>mvn -Pproducer exec:java -DsendType=converAndSend
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Sync :: JmsTemplate Example 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2:java (default-cli) @ jms-template >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2:java (default-cli) @ jms-template <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2:java (default-cli) @ jms-template ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.576s
[INFO] Finished at: Sat Nov 08 21:03:56 CET 2014
[INFO] Final Memory: 6M/159M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli) on project jms-template: An exception occured while executin

g the Java class. org.bsnyder.spring.jms.ProducerApp -> [Help 1]

The examples of the link
http://bsnyderblog.blogspot.de/2010/02/using-spring-to-receive-jms-messages.html
are also not correct.
public class SimpleMessageProducer {

the payload is not correct as it should be final, but can not be accessed in for loop
TextMessage message = session.createTextMessage(payload.toString());
you are accssing message.setIntProperty("messageCount", i);

None of your blog is error free.!!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.