You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Ramababu Bendalam <ha...@gmail.com> on 2016/02/09 19:07:56 UTC

Unable to consume all messages from the existing connection

Hi All,

Below is my scenario.

>From consumer side, I already have a connector. When I am using
connectionfactory to consume messages, it creates a new connection with my
local host name. Due to this the messages consumed are distributed between
the two connections. Finally i could not able to retrieve the actual
delivered  messages.

Is there is a way to use existing connection, without creating any new
connection.

Help is appreciated.

Thanks 
Ram.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Unable to consume all messages from the existing connection

Posted by Timothy Bish <ta...@gmail.com>.
On 02/10/2016 04:53 PM, Ramababu Bendalam wrote:
> HI Tim,
>
> Thank you for your reply. I have tried using pooled connections, but i do
> not find any option to get the existing connections. If you have any code
> related to that can you share it. Also please let me know how to use the
> reference of the existing connection using code.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311p4707403.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reference the API Docs to see what's available:
http://activemq.apache.org/maven/apidocs/org/apache/activemq/jms/pool/PooledConnectionFactory.html

Use Google to search on ActiveMQ Connection Pooling and read the tons of
questions on Stackoverflow and other blog posts that have already
covered the usage very very well.

Or you can cast your eyes on the unit tests for the connection pooling code:
https://github.com/apache/activemq/tree/master/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool

-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


Re: Unable to consume all messages from the existing connection

Posted by Ramababu Bendalam <ha...@gmail.com>.
HI Tim,

Thank you for your reply. I have tried using pooled connections, but i do
not find any option to get the existing connections. If you have any code
related to that can you share it. Also please let me know how to use the
reference of the existing connection using code.



--
View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311p4707403.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Unable to consume all messages from the existing connection

Posted by Timothy Bish <ta...@gmail.com>.
On 02/10/2016 04:01 PM, Tim Bain wrote:
> If you have a reference to an existing Connection and you want to reuse it,
> just use that instead of calling connectionFactory.createConnection() to
> create a new connection (as stated right in the method name).  Nothing
> requires you to create a new Connection if you already have one that will
> meet your needs.
> On Feb 10, 2016 10:52 AM, "Ramababu Bendalam" <ha...@gmail.com> wrote:

And if that doesn't meet the needs for some reason there is the
activemq-pool component which will do connection pooling for you.

>> Connection connection;
>> Destination queue;
>> Consumer consumer;
>>
>> ActiveMQConnectionFactory connectionFactory = new
>> ActiveMQConnectionFactory("tcp://<hostname>:61616");
>> connection = connectionFactory.createConnection();
>> connection.start();
>> session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
>> consumer = session.createConsumer(queue);
>> consumer.setMessageListener(messageListener);
>>
>> While creating connection to connectionfactory, it creates a new connection
>> with my localhostname.
>> But i do not want that in my case. As i have already have a connection
>> created. Is there is a way to use the existing connection instead of
>> creating a new connection.
>>
>> In my case the given destination have two connections(one which already
>> exists and the second one created during the test run) so the messages are
>> distributed between the two connections and i could not able to retrieve
>> the
>> exact consumed messages count.
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311p4707385.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>


-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


Re: Unable to consume all messages from the existing connection

Posted by Tim Bain <tb...@alumni.duke.edu>.
If you have a reference to an existing Connection and you want to reuse it,
just use that instead of calling connectionFactory.createConnection() to
create a new connection (as stated right in the method name).  Nothing
requires you to create a new Connection if you already have one that will
meet your needs.
On Feb 10, 2016 10:52 AM, "Ramababu Bendalam" <ha...@gmail.com> wrote:

> Connection connection;
> Destination queue;
> Consumer consumer;
>
> ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("tcp://<hostname>:61616");
> connection = connectionFactory.createConnection();
> connection.start();
> session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
> consumer = session.createConsumer(queue);
> consumer.setMessageListener(messageListener);
>
> While creating connection to connectionfactory, it creates a new connection
> with my localhostname.
> But i do not want that in my case. As i have already have a connection
> created. Is there is a way to use the existing connection instead of
> creating a new connection.
>
> In my case the given destination have two connections(one which already
> exists and the second one created during the test run) so the messages are
> distributed between the two connections and i could not able to retrieve
> the
> exact consumed messages count.
>
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311p4707385.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>

Re: Unable to consume all messages from the existing connection

Posted by Ramababu Bendalam <ha...@gmail.com>.
Connection connection;
Destination queue;
Consumer consumer;

ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://<hostname>:61616");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(queue);
consumer.setMessageListener(messageListener);

While creating connection to connectionfactory, it creates a new connection
with my localhostname. 
But i do not want that in my case. As i have already have a connection
created. Is there is a way to use the existing connection instead of
creating a new connection.

In my case the given destination have two connections(one which already
exists and the second one created during the test run) so the messages are
distributed between the two connections and i could not able to retrieve the
exact consumed messages count.





--
View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311p4707385.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Unable to consume all messages from the existing connection

Posted by Timothy Bish <ta...@gmail.com>.
On 02/09/2016 01:07 PM, Ramababu Bendalam wrote:
> Hi All,
>
> Below is my scenario.
>
> >From consumer side, I already have a connector. When I am using
> connectionfactory to consume messages, it creates a new connection with my
> local host name. Due to this the messages consumed are distributed between
> the two connections. Finally i could not able to retrieve the actual
> delivered  messages.
>
> Is there is a way to use existing connection, without creating any new
> connection.
>
> Help is appreciated.
>
> Thanks 
> Ram.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Unable-to-consume-all-messages-from-the-existing-connection-tp4707311.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
I think you need to clarify this a bit, perhaps with some code samples
etc, not clear what your trying to do.

-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/