Friday, June 12, 2009

New ActiveMQ-CPP tutorial posted

I took some time today to write a short tutorial on how to handle the advisory messages that ActiveMQ can send using the CPP client. Its still a work in progress but comments are welcome.

The tutorial is available here.

10 comments:

shaldar said...

Hi Tim - is there a way an asynch consumer can do a heartbeat check on the broker connection using the cms classes? I think this is very important for async consumer.

Tim said...

Currently we don't have an implementation of the Inactivity Monitor that is used in Java. I opened a new issue to implement it so it will make its way in at some point. We of course always welcome contributions.

susmit said...

Tim - Thanks for the information. I would be glad to implement this feature, since I need it somewhat urgently. Since I am new to both VC++ and this is my first attempt contributing to open source, I would need some guidance.

1) Wanted to know whether it is better to implement this feature in the cms namespace or activemq::core namespace

2) I see a "ping" feature in the Openwireconnector::connect method. I can write a "monitor" method that just uses the ping feature, along with exceptions. I am not clear on how to porpagate this method up to the final "connection" object I use. Could you give me some directions there?

3) If you some writeup on how to use submit activemq-cpp modifications for review,testing and commit - could you send it to me?

Tim said...

Well the way this should be done is to port the class InactivityMonitor from the Java ActiveMQ code over to the ActiveMQ-CPP client code. This class would end up being a TransportFilter and live in the activemq::transports namespace. The class functions by sending and receiving KeepAliveInfo messages using the Openwire binary protocol. The keep alive messages are sent on a periodic basis and as long as there are incoming or outgoing messages it doesn't need to do anything, the only time it kicks in is when there is either nothing being sent or nothing being received from the broker fr long periods.

susmit said...

Hi Tim

I might be missing something here - but it seems to me that that might already be there. I am using activemq-cpp 2.2.6 - and a file search showed a bunch of code related to maxInactivityDuration and KeepAliveInfo in the activemq::connector::openwire::commands namespace.

If this feature is indeed there - what is the best way to access it? I have been using the cms::connection which pretty much ignores extensions to the brokerURI. Is there a different namespace I should go to for more features? It will be very helpful if you could enumerate the high-level capabilities of different namespaces in your tutorials.

Tim said...

The maxInactivityDuration settings are sent to the Broker and affect on the amount of time that the broker will wait before terminating the client if it has been inactive for to long.

We process incoming KeepAliveInfo commands from the Broker right now in the ActiveMQConnection class in order to respond to the Brokers request to see if we are still alive. We don't currently send our own KeepAliveInfo commands out to the Broker in order to test that the broker is still alive and that our TCP socket hasn't been terminated by some event such as a switch fail.

Eventualy we need to create our own ersion of the InactivityMonitor simillar to the one that the Java code uses to perform the above tasks.

I would love to write more tutorials, and when I actually have more time I wil but just browsing the activemq-cpp source to examine the transports namespace and comparing it to the Java side transports namespace should give you an idea of what we need. Look at the java file InactivityMonitor.java and you will see how the Java client is dealing with testing its tcp connections and failing when they are inactive for to long.

Vinzenz said...

Hello Tim, is there any way to get the correct number of Messages in a Queue?
I try to use one of the latest versions of activemq-cpp, there is a function in the ActiveMQ Object called "getMessageAvailableCount", but these Function just return 0 all the time.

Tim said...

No, that sort of information isn't available to a JMS client, to get info about the underlying broker statistics you'd need to use the broker statistics plugin as described here:

http://activemq.apache.org/statisticsplugin.html

Vinzenz said...

Hi Tim, thanks for your reply. I'll try to use the Statisticplugin.
By the way, what is the function "getMessageAvailableCount" used for?

Tim said...

That will tell you how many messages are in the Consumers prefetch buffer.