You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by zaeem <za...@gmail.com> on 2017/07/26 13:38:49 UTC
How to find consumers on an exiting ActiveMQ Queue in c#
Is there a way in C# to do following
a) Find All Queues
b) For each Queue, find the count of consumers and Id/Name of Consumer
c) For each Queue, find the count of produces and Id/Name of Producer
I have used NMS but it does not give me a way of finding Consumer count for
a Queue or name of the consumer.
Zaeem
--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-exiting-ActiveMQ-Queue-in-c-tp4728927.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: How to find consumers on an existing ActiveMQ Queue in c#
Posted by bishalroy <Bi...@gmail.com>.
Please go through this link, this will describe step by step -
http://techadvizor.blogspot.com/2020/05/connecting-to-aws-mq-using-c-net.html
--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Re: How to find consumers on an exiting ActiveMQ Queue in c#
Posted by Timothy Bish <ta...@gmail.com>.
On 07/26/2017 12:01 PM, zaeem wrote:
> Below snippets lets you list Queues on the broker,Topics but i need
> something similar to list consumers on Queues for that broker by just
> passing a Queue Name.
No such API exists outside JMX, you have to do the work using only
advisories and statistics
>
> public const string QUEUE_ADVISORY_DESTINATION =
> "ActiveMQ.Advisory.Queue";
> public const string TOPIC_ADVISORY_DESTINATION =
> "ActiveMQ.Advisory.Topic";
> public const string TEMPQUEUE_ADVISORY_DESTINATION =
> "ActiveMQ.Advisory.TempQueue";
> public const string TEMPTOPIC_ADVISORY_DESTINATION =
> "ActiveMQ.Advisory.TempTopic";
>
> private static void Enumerate(string destination, Action<DestinationInfo>
> action)
> {
> IDestination dest = _session.GetTopic(destination);
> using (IMessageConsumer consumer =
> _session.CreateConsumer(dest))
> {
> IMessage advisory;
>
> while ((advisory =
> consumer.Receive(TimeSpan.FromMinutes(2000))) != null)
> {
> ActiveMQMessage am = advisory as ActiveMQMessage;
> if (am != null & am.DataStructure != null)
> {
> DestinationInfo info = am.DataStructure as
> DestinationInfo;
> if (info != null)
> {
> action(info);
> }
> }
> }
> }
> }
>
>
>
> public static void EnumerateQueues()
> {
> Console.WriteLine("Listing all Queues on Broker:");
> Enumerate(QUEUE_ADVISORY_DESTINATION, info =>
> Console.WriteLine(" Queue: " + info.Destination));
> Console.WriteLine("Listing Complete.");
> }
>
> public static void EnumerateTopics()
> {
> Console.WriteLine("Listing all Topics on Broker:");
> Enumerate(TOPIC_ADVISORY_DESTINATION, info =>
> Console.WriteLine(" Topic: " + info.Destination));
> Console.WriteLine("Listing Complete.");
>
> }
>
> public static void EnumerateDestinations()
> {
> Console.WriteLine("Listing all Destinations on Broker:");
> Enumerate(ALLDEST_ADVISORY_DESTINATION, info =>
> {
> string destType = info.Destination.IsTopic ? "Topic" :
> "Qeue";
> destType = info.Destination.IsTemporary ? "Temporary" +
> destType : destType;
> Console.WriteLine(" " + destType + ": " +
> info.Destination);
> });
> Console.WriteLine("Listing Complete.");
> }
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-existing-ActiveMQ-Queue-in-c-tp4728927p4728936.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/
Re: How to find consumers on an exiting ActiveMQ Queue in c#
Posted by zaeem <za...@gmail.com>.
Below snippets lets you list Queues on the broker,Topics but i need
something similar to list consumers on Queues for that broker by just
passing a Queue Name.
public const string QUEUE_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.Queue";
public const string TOPIC_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.Topic";
public const string TEMPQUEUE_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.TempQueue";
public const string TEMPTOPIC_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.TempTopic";
private static void Enumerate(string destination, Action<DestinationInfo>
action)
{
IDestination dest = _session.GetTopic(destination);
using (IMessageConsumer consumer =
_session.CreateConsumer(dest))
{
IMessage advisory;
while ((advisory =
consumer.Receive(TimeSpan.FromMinutes(2000))) != null)
{
ActiveMQMessage am = advisory as ActiveMQMessage;
if (am != null & am.DataStructure != null)
{
DestinationInfo info = am.DataStructure as
DestinationInfo;
if (info != null)
{
action(info);
}
}
}
}
}
public static void EnumerateQueues()
{
Console.WriteLine("Listing all Queues on Broker:");
Enumerate(QUEUE_ADVISORY_DESTINATION, info =>
Console.WriteLine(" Queue: " + info.Destination));
Console.WriteLine("Listing Complete.");
}
public static void EnumerateTopics()
{
Console.WriteLine("Listing all Topics on Broker:");
Enumerate(TOPIC_ADVISORY_DESTINATION, info =>
Console.WriteLine(" Topic: " + info.Destination));
Console.WriteLine("Listing Complete.");
}
public static void EnumerateDestinations()
{
Console.WriteLine("Listing all Destinations on Broker:");
Enumerate(ALLDEST_ADVISORY_DESTINATION, info =>
{
string destType = info.Destination.IsTopic ? "Topic" :
"Qeue";
destType = info.Destination.IsTemporary ? "Temporary" +
destType : destType;
Console.WriteLine(" " + destType + ": " +
info.Destination);
});
Console.WriteLine("Listing Complete.");
}
--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-existing-ActiveMQ-Queue-in-c-tp4728927p4728936.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: How to find consumers on an exiting ActiveMQ Queue in c#
Posted by Timothy Bish <ta...@gmail.com>.
On 07/26/2017 11:56 AM, zaeem wrote:
> I have already checked the examples. Those let you create a queue or create a
> consumer and producer on existing queue or new queue. I'm only after finding
> information on an Existing Queue and how many producers there are under that
> queue.
The example on SO does much of what you want, have you actually tried
it? Did you ensure that the statistics broker plugin is installed on
your broker?
>
> So Im able to successfully connect to AMQ using the snippet below
>
> Uri connecturi = new Uri("activemq:tcp://****:61616");
> IConnectionFactory factory = new
> NMSConnectionFactory(connecturi);
>
> using (_connection = factory.CreateConnection())
> {
> _connection.Start();
> using (_session = _connection.CreateSession())
> {
> /// Now here i should be able to check for a queue and the number of
> consumers it has
> /// Same thing for finding number of producers on that queue
> }
>
> Now on AMQ i have around 12 Queues for which i need information about.
>
> One Queue Example is Lets say "Test.Queue" which has 5 consumers. I need to
> know these 5 consumers on this queue
The statistics plugin won't give you consumer IDs, only a count of the
consumers and producers on a destination. You can try and figure out
the information by listening in on advisory destinations as I've already
said, I'd suggest you do some experimentation there.
> What or how would i write the c# equivalent code to access this queue using
> NMS and statistical plugin.
> The example on the URL is java based. Sorry im not been able to get around
> this issue and seems like there is no way other than writing something in
> Java
Since NMS is essentially the JMS API mapped to a .NET workflow the
translation of a Java sample to a C# sample should be trivial.
> Thanks,
> Z
>
>
>
>
>
> }
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-existing-ActiveMQ-Queue-in-c-tp4728927p4728935.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/
Re: How to find consumers on an exiting ActiveMQ Queue in c#
Posted by zaeem <za...@gmail.com>.
I have already checked the examples. Those let you create a queue or create a
consumer and producer on existing queue or new queue. I'm only after finding
information on an Existing Queue and how many producers there are under that
queue.
So Im able to successfully connect to AMQ using the snippet below
Uri connecturi = new Uri("activemq:tcp://****:61616");
IConnectionFactory factory = new
NMSConnectionFactory(connecturi);
using (_connection = factory.CreateConnection())
{
_connection.Start();
using (_session = _connection.CreateSession())
{
/// Now here i should be able to check for a queue and the number of
consumers it has
/// Same thing for finding number of producers on that queue
}
Now on AMQ i have around 12 Queues for which i need information about.
One Queue Example is Lets say "Test.Queue" which has 5 consumers. I need to
know these 5 consumers on this queue
What or how would i write the c# equivalent code to access this queue using
NMS and statistical plugin.
The example on the URL is java based. Sorry im not been able to get around
this issue and seems like there is no way other than writing something in
Java
Thanks,
Z
}
--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-existing-ActiveMQ-Queue-in-c-tp4728927p4728935.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: How to find consumers on an exiting ActiveMQ Queue in c#
Posted by Timothy Bish <ta...@gmail.com>.
On 07/26/2017 09:38 AM, zaeem wrote:
> Is there a way in C# to do following
>
>
> a) Find All Queues
>
> b) For each Queue, find the count of consumers and Id/Name of Consumer
>
> c) For each Queue, find the count of produces and Id/Name of Producer
>
> I have used NMS but it does not give me a way of finding Consumer count for
> a Queue or name of the consumer.
>
> Zaeem
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-exiting-ActiveMQ-Queue-in-c-tp4728927.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
You can use the Statistics Broker plugin to query for information on the
destination in question.
http://activemq.apache.org/statisticsplugin.html
There's even a nice example on StackOverflow on using it with C#
https://stackoverflow.com/questions/15746391/how-to-access-the-activemq-statistics-plugin-in-net
To gather other information on the broker from .NET you could monitor
advisory topics like the producer / consumer instances which will tell
you a bit about what is going on at the broker side as well.
http://activemq.apache.org/advisory-message.html
--
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/