tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From KDillon <myfakespamemaila...@gmail.com>
Subject Re: JMSXGroupID and TomEE's JMS Connection Factory
Date Thu, 25 Aug 2016 14:44:26 GMT
I have two classes

@Path("/")
public class HelloWorld {

	@Resource(name = "AnswerQueue")
	private Queue AnswerQueue;

	@Resource
	private ConnectionFactory connectionFactory;

	@GET
	public String home(){
		try {
			Connection connection = connectionFactory.createConnection();
			connection.start();

			// Create a Session
			Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);

			// Create a MessageProducer from the Session to the Topic or Queue
			MessageProducer producer = session.createProducer(AnswerQueue);

			MessageConsumer consumer1 = session.createConsumer(AnswerQueue);
			consumer1.setMessageListener(new Consumer("Consumer1"));

			MessageConsumer consumer2 = session.createConsumer(AnswerQueue);
			consumer2.setMessageListener(new Consumer("Consumer2"));


			for(int i=0; i<1000; i++){
				// Create a message
				TextMessage message = session.createTextMessage("Hello World! " + i);
				message.setStringProperty("JMSXGroupID","group1");

				// Tell the producer to send the message
				producer.send(message);
			}


		}catch(JMSException e){

		}

		return "Hello World";
	}
}


public class Consumer implements MessageListener {
	private String consumerName;

	public Consumer(String consumerName) {
		this.consumerName = consumerName;
	}

	public void onMessage(Message message) {
		TextMessage textMessage = (TextMessage) message;
		try {
			System.out.println(consumerName + " " + Thread.currentThread().getId() +
" received "
					+ textMessage.getText());
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}

The output I see when I hit the end point is 

Consumer1 97 received Hello World! 13
Consumer1 97 received Hello World! 14
Consumer1 97 received Hello World! 15
Consumer1 99 received Hello World! 16
Consumer1 99 received Hello World! 17
......
Consumer1 99 received Hello World! 237
Consumer1 99 received Hello World! 238
Consumer1 97 received Hello World! 239
Consumer1 97 received Hello World! 240
Consumer1 97 received Hello World! 241
Consumer1 97 received Hello World! 242
Consumer1 97 received Hello World! 243
Consumer1 97 received Hello World! 244
Consumer1 97 received Hello World! 245


I would see two different threads handling the messages and it would go back
and forth between them.  Is it normal to see different threads handling the
message?  I would've expected one thread to handle everything.  



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/JMSXGroupID-and-TomEE-s-JMS-Connection-Factory-tp4679868p4679885.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Mime
View raw message