tpamsler schrieb:
Hello,

I am trying to figure out if I need to create a new session for every
message that I produce and or consume?

For example do I need to do the following to send two messages:

// Sending MSG1
session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer1 = session1.createProducer(maintenanceDestination);
TextMessage textMessage1 = session1.createTextMessage("Hello World 1");
messageProducer1.send(textMessage1);
session1.close();

// Sending MSG2
session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer2 = session2.createProducer(maintenanceDestination);
TextMessage textMessage2 = session2.createTextMessage("Hello World 2");
messageProducer2.send(textMessage2);
session2.close();

Or can I send more than one message using the same session:

// Sending MSG1 and MSG2
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(maintenanceDestination);
TextMessage textMessage1 = session.createTextMessage("Hello World 1");
TextMessage textMessage2 = session.createTextMessage("Hello World 2");
messageProducer.send(textMessage1);
messageProducer.send(textMessage2);
session.close();

-------------
If both are possible, what are the pros/cons for doing it either way?
If I can send more than one message, is there a limit on how many messages I
can/should send per session?

Best,
-- Thomas

You only need one session for your Messages. So your 2nd example is ok.

Reply via email to