activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alanchb <alanchbm...@gmail.com>
Subject RE: How to post message to a certain queue consumer?
Date Wed, 19 May 2010 09:48:04 GMT

I wrote code to test multiple consumers with same selector under P2P. The
message from producer will be sent to different consumers by turns.


Cristian Botiza wrote:
> 
> On a different note...
> The original post mentioned P2P (that is Queues), the examples are about
> Topics (pub sub).
> In the case of P2P there is at most one receiver that gets the message
> anyways. Was wondering
> if selectors are trully useful in this case, especially with multiple
> consumers.
> When ActiveMQ selects the consumer for a message, does it evaluate the
> selectors for all consumers?
> 
> Many thanks.
> 
> ________________________________________
> From: Sebastian Rodriguez [srodrigu85@gmail.com]
> Sent: 19 May 2010 11:42
> To: users@activemq.apache.org
> Subject: Re: How to post message to a certain queue consumer?
> 
> Hi alan,
> For the Selectors in C#, you can find the following snippet:
> <--- start producer side code -->
>         /// <summary>
>         /// True if the publisher has a selector. False otherwise
>         /// </summary>
>         /// <value>
>         /// <c>true</c> if this instance is selector; otherwise,
> <c>false</c>.
>         /// </value>
>         public bool IsSelector
>         {
>             get { return m_isSelector; }
>             set { m_isSelector = value; }
>         }
>         private bool m_isSelector = false;
> 
>         /// <summary>
>         /// Value of the Publisher's selector.
>         /// </summary>
>         /// <value>The selector.</value>
>         public string Selector
>         {
>             get { return m_selector; }
>             set { m_selector = value; }
>         }
>         private string m_selector = "default";
> 
> #region ITopicPublisher Implementation
>         /// <summary>
>         /// Fires the notification.
>         /// </summary>
>         /// The body.
>         public void FireNotification(object body)
>         {
>             if (!m_isDisposed)
>             {
>                 try
>                 {
>                     IObjectMessage objMessage = null;
>                     objMessage = m_producer.CreateObjectMessage(body);
>                     m_producer.DeliveryMode = MsgDeliveryMode.Persistent;
>                     objMessage.NMSPriority = m_messagePriority;
>                     objMessage.NMSTimeToLive = m_timeToLive;
> 
>                     if (IsSelector)
>                     {
>                         objMessage.Properties.SetString("eventName",
> Selector);
>                     }
> 
>                     m_producer.Send(objMessage);
>                 }
>                 catch (Exception ex)
>                 {
>                     Logger.Exception(ex);
>                 }
>             }
>             else
>             {
>                 ObjectDisposedException ex = new ObjectDisposedException(
>                     this.GetType().FullName);
> 
>                 Logger.Exception(ex);
>                 throw ex;
>             }
>         }
>         #endregion
> <--- end producer side code -->
> 
> <--- start consumer side code -->
>         /// <summary>
>         /// <see cref="ITopicConnection"/>
>         /// </summary>
>         public ITopicSubscriber CreateTopicSubscriber(string selector)
>         {
>             // default selector (condition always true)
>             string finalSelector = "2 > 1";
> 
>             try
>             {
>                 if (!String.IsNullOrEmpty(selector))
>                 {
>                     finalSelector = string.Format("eventName = '{0}'",
> selector);
>                 }
> 
>                 IMessageConsumer consumer =
> m_session.CreateConsumer(m_topic, finalSelector, false);
>                 return new ActiveMQSubscriber(consumer);
>             }
>             catch (Exception ex)
>             {
>                 Logger.Exception(ex);
>                 throw;
>             }
>         }
> 
> <--- end consumer side code -->
> 
> This is just a snippet that is not really intended to work but express the
> main idea:
> to use the selector you need to set it in the producer side (via the
> Message.Properties.SetString), then when you create a consumer, you need
> to
> specify if it has a selector or not (via the CreateConsumer)
> 
> I found the tutorials in these page quite useful while learning the basics
> of ActiveMQ with C# (via the Apache.NMS.ActiveMQ):
> http://remark.wordpress.com/articles/publish-subscribe-with-activemq-and-nms/
> The author of this blog have a bunch of ActiveMQ related blog entries that
> are worth reading.
> Hope this helps you,
> Seb
> 
> On 19 May 2010 16:22, Cristian Botiza <Cristian.Botiza@endava.com> wrote:
> 
>> Session session = ...;
>> MessageProducer producer = session.createProducer(destination);
>>
>> producer.setTimeToLive(timeToLiveInMilliseconds); //use the producer API
>> to
>> set TTL
>>
>> Message message = session.create...Message(...);
>>
>> producer.send(message);
>>
>> TTL has nothing to do with message selectors; I found it useful though.
>> ________________________________________
>> From: alanchb [alanchbmail@gmail.com]
>> Sent: 19 May 2010 04:32
>> To: users@activemq.apache.org
>> Subject: RE: How to post message to a certain queue consumer?
>>
>> Yes,it works well.
>> But I work with Visual C#,the method is a little different from yours.
>> Can you give me some guide about TTL you mentioned in early reply?
>>
>>
>> Cristian Botiza wrote:
>> >
>> > This is not AMQ specific; it's rather JMS API specific - the JavaDoc of
>> > interface javax.jms.Message.
>> > Did this approach work with P2P and multiple consumers?
>> >
>> > ________________________________________
>> > From: alanchb [alanchbmail@gmail.com]
>> > Sent: 18 May 2010 18:08
>> > To: users@activemq.apache.org
>> > Subject: RE: How to post message to a certain queue consumer?
>> >
>> > thanks a lot! that's exactly what i need.
>> > but if i did not post the question here and get your kind reply,i will
>> > never
>> > think of  using the method message.setStringProperty to set message
>> > selector.how do you konw this?is there any shortcut to learn about
>> > ActiveMQ?
>> >
>> >
>> > Cristian Botiza wrote:
>> >>
>> >> In the producer code, when creating the Message object:
>> >>
>> >> message.setStringProperty("myFilterProperty", "my consumerID");
>> >>
>> >> In the consumer (QueueReceiver or Message Driven Bean), define the
>> >> message
>> >> selector expression (SQL syntax) as myFilterPropert='my consumerID'
>> >>
>> >> ActiveMQ should dispatch only the messages matching the filter. Others
>> >> will stay in the queue, I would also set the TTL in the producer
>> >> (optional
>> >> though).
>> >>
>> >> ________________________________________
>> >> From: alanchb [alanchbmail@gmail.com]
>> >> Sent: 18 May 2010 12:24
>> >> To: users@activemq.apache.org
>> >> Subject: RE: How to post message to a certain queue consumer?
>> >>
>> >> Thanks for your reply.
>> >>
>> >> but how to use message selector to identify a consumer when producer
>> send
>> >> a
>> >> message?
>> >>
>> >>
>> >> Cristian Botiza wrote:
>> >>>
>> >>> Message selectors?
>> >>>
>> >>> ________________________________________
>> >>> From: alanchb [alanchbmail@gmail.com]
>> >>> Sent: 18 May 2010 11:12
>> >>> To: users@activemq.apache.org
>> >>> Subject: How to post message to a certain queue consumer?
>> >>>
>> >>> under the P2P mode,if i have sevaral queue consumers,how to make the
>> >>> producer
>> >>> post message to the consumer he wants?
>> >>> --
>> >>> View this message in context:
>> >>>
>> http://old.nabble.com/How-to-post-message-to-a-certain-queue-consumer--tp28592826p28592826.html
>> >>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> >>>
>> >>> The information in this email is confidential and may be legally
>> >>> privileged. It is intended solely for the addressee. Any opinions
>> >>> expressed are mine and do not necessarily represent the opinions of
>> the
>> >>> Company. Emails are susceptible to interference. If you are not the
>> >>> intended recipient, any disclosure, copying, distribution or any
>> action
>> >>> taken or omitted to be taken in reliance on it, is strictly
>> prohibited
>> >>> and
>> >>> may be unlawful. If you have received this message in error, do not
>> open
>> >>> any attachments but please notify the EndavaIT Service Desk on (+44
>> >>> (0)870
>> >>> 423 0187), and delete this message from your system. The sender
>> accepts
>> >>> no
>> >>> responsibility for information, errors or omissions in this email, or
>> >>> for
>> >>> its use or misuse, or for any act committed or omitted in connection
>> >>> with
>> >>> this communication. If in doubt, please verify the authenticity of
>> the
>> >>> contents with the sender. Please rely on your own virus checkers as
>> no
>> >>> responsibility is taken by the sender for any damage rising out of
>> any
>> >>> bug
>> >>> or virus infection.
>> >>>
>> >>> Endava Limited is a company registered in England under company
>> number
>> >>> 5722669 whose registered office is at 125 Old Broad Street, London,
>> EC2N
>> >>> 1AR, United Kingdom. Endava Limited is the Endava group holding
>> company
>> >>> and does not provide any services to clients. Each of Endava Limited
>> and
>> >>> its subsidiaries is a separate legal entity and has no liability for
>> >>> another such entity's acts or omissions. Please refer to the “Legal”
>> >>> section on our website for a list of legal entities.
>> >>>
>> >>>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/How-to-post-message-to-a-certain-queue-consumer--tp28592826p28593473.html
>> >> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> >>
>> >> The information in this email is confidential and may be legally
>> >> privileged. It is intended solely for the addressee. Any opinions
>> >> expressed are mine and do not necessarily represent the opinions of
>> the
>> >> Company. Emails are susceptible to interference. If you are not the
>> >> intended recipient, any disclosure, copying, distribution or any
>> action
>> >> taken or omitted to be taken in reliance on it, is strictly prohibited
>> >> and
>> >> may be unlawful. If you have received this message in error, do not
>> open
>> >> any attachments but please notify the EndavaIT Service Desk on (+44
>> >> (0)870
>> >> 423 0187), and delete this message from your system. The sender
>> accepts
>> >> no
>> >> responsibility for information, errors or omissions in this email, or
>> for
>> >> its use or misuse, or for any act committed or omitted in connection
>> with
>> >> this communication. If in doubt, please verify the authenticity of the
>> >> contents with the sender. Please rely on your own virus checkers as no
>> >> responsibility is taken by the sender for any damage rising out of any
>> >> bug
>> >> or virus infection.
>> >>
>> >> Endava Limited is a company registered in England under company number
>> >> 5722669 whose registered office is at 125 Old Broad Street, London,
>> EC2N
>> >> 1AR, United Kingdom. Endava Limited is the Endava group holding
>> company
>> >> and does not provide any services to clients. Each of Endava Limited
>> and
>> >> its subsidiaries is a separate legal entity and has no liability for
>> >> another such entity's acts or omissions. Please refer to the “Legal”
>> >> section on our website for a list of legal entities.
>> >>
>> >>
>> >
>> > --
>> > View this message in context:
>> >
>> http://old.nabble.com/How-to-post-message-to-a-certain-queue-consumer--tp28592826p28597231.html
>> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> >
>> > The information in this email is confidential and may be legally
>> > privileged. It is intended solely for the addressee. Any opinions
>> > expressed are mine and do not necessarily represent the opinions of the
>> > Company. Emails are susceptible to interference. If you are not the
>> > intended recipient, any disclosure, copying, distribution or any action
>> > taken or omitted to be taken in reliance on it, is strictly prohibited
>> and
>> > may be unlawful. If you have received this message in error, do not
>> open
>> > any attachments but please notify the EndavaIT Service Desk on (+44
>> (0)870
>> > 423 0187), and delete this message from your system. The sender accepts
>> no
>> > responsibility for information, errors or omissions in this email, or
>> for
>> > its use or misuse, or for any act committed or omitted in connection
>> with
>> > this communication. If in doubt, please verify the authenticity of the
>> > contents with the sender. Please rely on your own virus checkers as no
>> > responsibility is taken by the sender for any damage rising out of any
>> bug
>> > or virus infection.
>> >
>> > Endava Limited is a company registered in England under company number
>> > 5722669 whose registered office is at 125 Old Broad Street, London,
>> EC2N
>> > 1AR, United Kingdom. Endava Limited is the Endava group holding company
>> > and does not provide any services to clients. Each of Endava Limited
>> and
>> > its subsidiaries is a separate legal entity and has no liability for
>> > another such entity's acts or omissions. Please refer to the “Legal”
>> > section on our website for a list of legal entities.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/How-to-post-message-to-a-certain-queue-consumer--tp28592826p28603302.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>> The information in this email is confidential and may be legally
>> privileged. It is intended solely for the addressee. Any opinions
>> expressed
>> are mine and do not necessarily represent the opinions of the Company.
>> Emails are susceptible to interference. If you are not the intended
>> recipient, any disclosure, copying, distribution or any action taken or
>> omitted to be taken in reliance on it, is strictly prohibited and may be
>> unlawful. If you have received this message in error, do not open any
>> attachments but please notify the EndavaIT Service Desk on (+44 (0)870
>> 423
>> 0187), and delete this message from your system. The sender accepts no
>> responsibility for information, errors or omissions in this email, or for
>> its use or misuse, or for any act committed or omitted in connection with
>> this communication. If in doubt, please verify the authenticity of the
>> contents with the sender. Please rely on your own virus checkers as no
>> responsibility is taken by the sender for any damage rising out of any
>> bug
>> or virus infection.
>>
>> Endava Limited is a company registered in England under company number
>> 5722669 whose registered office is at 125 Old Broad Street, London, EC2N
>> 1AR, United Kingdom. Endava Limited is the Endava group holding company
>> and
>> does not provide any services to clients. Each of Endava Limited and its
>> subsidiaries is a separate legal entity and has no liability for another
>> such entity's acts or omissions. Please refer to the “Legal” section on
>> our
>> website for a list of legal entities.
>>
> 
> 
> 
> --
> Sebastien Rodriguez
> 
> The information in this email is confidential and may be legally
> privileged. It is intended solely for the addressee. Any opinions
> expressed are mine and do not necessarily represent the opinions of the
> Company. Emails are susceptible to interference. If you are not the
> intended recipient, any disclosure, copying, distribution or any action
> taken or omitted to be taken in reliance on it, is strictly prohibited and
> may be unlawful. If you have received this message in error, do not open
> any attachments but please notify the EndavaIT Service Desk on (+44 (0)870
> 423 0187), and delete this message from your system. The sender accepts no
> responsibility for information, errors or omissions in this email, or for
> its use or misuse, or for any act committed or omitted in connection with
> this communication. If in doubt, please verify the authenticity of the
> contents with the sender. Please rely on your own virus checkers as no
> responsibility is taken by the sender for any damage rising out of any bug
> or virus infection.
> 
> Endava Limited is a company registered in England under company number
> 5722669 whose registered office is at 125 Old Broad Street, London, EC2N
> 1AR, United Kingdom. Endava Limited is the Endava group holding company
> and does not provide any services to clients. Each of Endava Limited and
> its subsidiaries is a separate legal entity and has no liability for
> another such entity's acts or omissions. Please refer to the “Legal”
> section on our website for a list of legal entities.
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-post-message-to-a-certain-queue-consumer--tp28592826p28606114.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message