activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Buss <marco.b...@gmx.de>
Subject Re: Using one session per message
Date Sun, 27 Jan 2008 00:08:56 GMT
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.

Mime
View raw message