You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by tpamsler <tp...@ucdavis.edu> on 2008/01/27 00:36:19 UTC

Using one session per message

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

-- 
View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114117.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Using one session per message

Posted by Rob Davies <ra...@gmail.com>.
thx James - I need caffeine!

On Jan 28, 2008, at 7:20 AM, James Strachan wrote:

> Its called failover the URI to use btw...
> http://activemq.apache.org/how-do-i-configure-automatic-reconnection.html
>
>
> On 28/01/2008, Rob Davies <ra...@gmail.com> wrote:
>>
>> On Jan 27, 2008, at 9:28 PM, Marco Buss wrote:
>>
>>> Rob Davies schrieb:
>>>>
>>>> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
>>>>
>>>>>
>>>>> Marco,
>>>>>
>>>>> Thank you for the response.  Are there limitations on how long a
>>>>> session can
>>>>> stay open and the number of messages it can handle? If I use the
>>>>> 2nd example
>>>>> in our application, the session may stay open for a few weeks.
>>>>>
>>>>> Best,
>>>>> -- Thomas
>>>>>
>>>>>
>>>>> Marco Buss wrote:
>>>>>>
>>>>>> You only need one session for your Messages. So your 2nd example
>>>>>> is ok.
>>>>>>
>>>>>
>>>>> --View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
>>>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>>>
>>>> There is no limit to how long a session is open - so weeks will be
>>>> ok ;)
>>>>
>>>> cheers,
>>>>
>>>> Rob
>>> And what happens if the connection fails (timeout on tcp)?
>>
>> If you use the reliable transport you get automatic reconnection -  
>> see http://activemq.apache.org/uri-protocols.html
>> This includes getting a replay of the clients state - so from the
>> developers point of view, a failure/reconnect is seamless.
>>
>> cheers,
>>
>> Rob
>>
>>
>
>
> -- 
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com


Re: Using one session per message

Posted by James Strachan <ja...@gmail.com>.
The inactivity duration is just a way of the transport detecting early
that a socket is actually dead - failover will still work without it -
it just might take a while for your OS to realise a socket is actually
dead. There have been a number of bug fixes in trunk lately around
that; so try 5.1-SNAPSHOT

On 28/01/2008, Marco Buss <ma...@gmx.de> wrote:
> I think that is not what i mean. I have a situation at testing activemq
> performance, where on a longer time period nothing happens at a connection.
> And so an Exception occurrs and i cant send other messages. I set
> wireFormat.maxInactivityDuration=0 to change that.
> If i understand it correctly the failover only works if i set the
> failover connection, and not in that way to connect to the same uri.
>
> James Strachan schrieb:
> > Its called failover the URI to use btw...
> > http://activemq.apache.org/how-do-i-configure-automatic-reconnection.html
> >
> >
> > On 28/01/2008, Rob Davies <ra...@gmail.com> wrote:
> >
> >> On Jan 27, 2008, at 9:28 PM, Marco Buss wrote:
> >>
> >>
> >>> Rob Davies schrieb:
> >>>
> >>>> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
> >>>>
> >>>>
> >>>>> Marco,
> >>>>>
> >>>>> Thank you for the response.  Are there limitations on how long a
> >>>>> session can
> >>>>> stay open and the number of messages it can handle? If I use the
> >>>>> 2nd example
> >>>>> in our application, the session may stay open for a few weeks.
> >>>>>
> >>>>> Best,
> >>>>> -- Thomas
> >>>>>
> >>>>>
> >>>>> Marco Buss wrote:
> >>>>>
> >>>>>> You only need one session for your Messages. So your 2nd example
> >>>>>> is ok.
> >>>>>>
> >>>>>>
> >>>>> --View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
> >>>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >>>>>
> >>>>>
> >>>> There is no limit to how long a session is open - so weeks will be
> >>>> ok ;)
> >>>>
> >>>> cheers,
> >>>>
> >>>> Rob
> >>>>
> >>> And what happens if the connection fails (timeout on tcp)?
> >>>
> >> If you use the reliable transport you get automatic reconnection - see http://activemq.apache.org/uri-protocols.html
> >> This includes getting a replay of the clients state - so from the
> >> developers point of view, a failure/reconnect is seamless.
> >>
> >> cheers,
> >>
> >> Rob
> >>
> >>
> >>
> >
> >
> >
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Using one session per message

Posted by Marco Buss <ma...@gmx.de>.
I think that is not what i mean. I have a situation at testing activemq 
performance, where on a longer time period nothing happens at a connection.
And so an Exception occurrs and i cant send other messages. I set 
wireFormat.maxInactivityDuration=0 to change that.
If i understand it correctly the failover only works if i set the 
failover connection, and not in that way to connect to the same uri.

James Strachan schrieb:
> Its called failover the URI to use btw...
> http://activemq.apache.org/how-do-i-configure-automatic-reconnection.html
>
>
> On 28/01/2008, Rob Davies <ra...@gmail.com> wrote:
>   
>> On Jan 27, 2008, at 9:28 PM, Marco Buss wrote:
>>
>>     
>>> Rob Davies schrieb:
>>>       
>>>> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
>>>>
>>>>         
>>>>> Marco,
>>>>>
>>>>> Thank you for the response.  Are there limitations on how long a
>>>>> session can
>>>>> stay open and the number of messages it can handle? If I use the
>>>>> 2nd example
>>>>> in our application, the session may stay open for a few weeks.
>>>>>
>>>>> Best,
>>>>> -- Thomas
>>>>>
>>>>>
>>>>> Marco Buss wrote:
>>>>>           
>>>>>> You only need one session for your Messages. So your 2nd example
>>>>>> is ok.
>>>>>>
>>>>>>             
>>>>> --View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
>>>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>>>
>>>>>           
>>>> There is no limit to how long a session is open - so weeks will be
>>>> ok ;)
>>>>
>>>> cheers,
>>>>
>>>> Rob
>>>>         
>>> And what happens if the connection fails (timeout on tcp)?
>>>       
>> If you use the reliable transport you get automatic reconnection - see http://activemq.apache.org/uri-protocols.html
>> This includes getting a replay of the clients state - so from the
>> developers point of view, a failure/reconnect is seamless.
>>
>> cheers,
>>
>> Rob
>>
>>
>>     
>
>
>   


Re: Using one session per message

Posted by James Strachan <ja...@gmail.com>.
Its called failover the URI to use btw...
http://activemq.apache.org/how-do-i-configure-automatic-reconnection.html


On 28/01/2008, Rob Davies <ra...@gmail.com> wrote:
>
> On Jan 27, 2008, at 9:28 PM, Marco Buss wrote:
>
> > Rob Davies schrieb:
> >>
> >> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
> >>
> >>>
> >>> Marco,
> >>>
> >>> Thank you for the response.  Are there limitations on how long a
> >>> session can
> >>> stay open and the number of messages it can handle? If I use the
> >>> 2nd example
> >>> in our application, the session may stay open for a few weeks.
> >>>
> >>> Best,
> >>> -- Thomas
> >>>
> >>>
> >>> Marco Buss wrote:
> >>>>
> >>>> You only need one session for your Messages. So your 2nd example
> >>>> is ok.
> >>>>
> >>>
> >>> --View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
> >>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >>>
> >> There is no limit to how long a session is open - so weeks will be
> >> ok ;)
> >>
> >> cheers,
> >>
> >> Rob
> > And what happens if the connection fails (timeout on tcp)?
>
> If you use the reliable transport you get automatic reconnection - see http://activemq.apache.org/uri-protocols.html
> This includes getting a replay of the clients state - so from the
> developers point of view, a failure/reconnect is seamless.
>
> cheers,
>
> Rob
>
>


-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Using one session per message

Posted by Rob Davies <ra...@gmail.com>.
On Jan 27, 2008, at 9:28 PM, Marco Buss wrote:

> Rob Davies schrieb:
>>
>> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
>>
>>>
>>> Marco,
>>>
>>> Thank you for the response.  Are there limitations on how long a  
>>> session can
>>> stay open and the number of messages it can handle? If I use the  
>>> 2nd example
>>> in our application, the session may stay open for a few weeks.
>>>
>>> Best,
>>> -- Thomas
>>>
>>>
>>> Marco Buss wrote:
>>>>
>>>> You only need one session for your Messages. So your 2nd example  
>>>> is ok.
>>>>
>>>
>>> --View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
>>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>>
>> There is no limit to how long a session is open - so weeks will be  
>> ok ;)
>>
>> cheers,
>>
>> Rob
> And what happens if the connection fails (timeout on tcp)?

If you use the reliable transport you get automatic reconnection - see http://activemq.apache.org/uri-protocols.html
This includes getting a replay of the clients state - so from the  
developers point of view, a failure/reconnect is seamless.

cheers,

Rob


Re: Using one session per message

Posted by Marco Buss <ma...@gmx.de>.
Rob Davies schrieb:
>
> On Jan 27, 2008, at 12:22 AM, tpamsler wrote:
>
>>
>> Marco,
>>
>> Thank you for the response.  Are there limitations on how long a 
>> session can
>> stay open and the number of messages it can handle? If I use the 2nd 
>> example
>> in our application, the session may stay open for a few weeks.
>>
>> Best,
>> -- Thomas
>>
>>
>> Marco Buss wrote:
>>>
>>> You only need one session for your Messages. So your 2nd example is ok.
>>>
>>
>> --View this message in context: 
>> http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html 
>>
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
> There is no limit to how long a session is open - so weeks will be ok ;)
>
> cheers,
>
> Rob
And what happens if the connection fails (timeout on tcp)?

Re: Using one session per message

Posted by Rob Davies <ra...@gmail.com>.
On Jan 27, 2008, at 12:22 AM, tpamsler wrote:

>
> Marco,
>
> Thank you for the response.  Are there limitations on how long a  
> session can
> stay open and the number of messages it can handle? If I use the 2nd  
> example
> in our application, the session may stay open for a few weeks.
>
> Best,
> -- Thomas
>
>
> Marco Buss wrote:
>>
>> You only need one session for your Messages. So your 2nd example is  
>> ok.
>>
>
> -- 
> View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
There is no limit to how long a session is open - so weeks will be ok ;)

cheers,

Rob


Re: Using one session per message

Posted by tpamsler <tp...@ucdavis.edu>.
Marco,

Thank you for the response.  Are there limitations on how long a session can
stay open and the number of messages it can handle? If I use the 2nd example
in our application, the session may stay open for a few weeks.

Best,
-- Thomas


Marco Buss wrote:
> 
> You only need one session for your Messages. So your 2nd example is ok.
> 

-- 
View this message in context: http://www.nabble.com/Using-one-session-per-message-tp15114117s2354p15114519.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Using one session per message

Posted by Marco Buss <ma...@gmx.de>.
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.