How to get a count of messages on IBM Websphere Queue - java

I'm using XMS (i.e IBM Message Services Client for .NET) to connect to IBM MQ and get the messages.
With that said, I wanted to know how to get count of messages on a Queue at any given point of time.
(Explored on IQueueBrowser.GetEnumerator, but it will download the messages onto client.)

XMS .NET is an implementation of JMS specification and JMS specific does not define a method or a property that retrieves count of messages in a queue. Hence XMS does not provide a way to do that.
Anything to do with queue attributes is a provider specific administrative job, so you have to use message provider specific APIs.
But why do you want to know the count of messages? Application should be coded to receive messages continuously. Your application can choose to quit receiving messages when there are no more messages in the queue or wait for further messages. If there are no messages, the receive call will return with null message object. Your application can check for this and decide to make further receive calls or quit.
HTH

Related

How to Listen to Rabbit MQ queues with different names in java spring?

I have a chat app that will create a queue for each user that is online and I'm trying to get all the queued messages for this user and the problem is that I only know the name of the queue through the message that comes through and therefore I cant use #RabbitListener to give it a queue name.
Is there any way that I can get all the message queued for a user other than using rabbitTemplate
convert ? since it only gives me one single message other than all of them
I would say it is better to look into a STOMP over WebSocket protocol which is supported as a plugin on RabbitMQ. It indeed creates an individual queue for every user and there is a mechanism to consume all the messages sent to that user.
See WebSocket support in Spring Framework: https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#websocket
If you can't do that, you probably should look into a custom solution where you send a queue name to some static exchange for the consumer to be aware of such a new queue which you can add to the ListenerContainer at runtime (and remove respectively later). See more info in Spring AMQP: https://docs.spring.io/spring-amqp/docs/current/reference/html/#listener-queues

how to get notification from server when ever it is on

Is there any way to get notification from server whenever it is on?
my requirement is when ever ActiveMQ is on a piece of code will run automatically
in ActiveMQ is there is no load on startup
Create a publisher in your language of choice that periodically sends a test message to ActiveMQ.
Create a subscriber in your language of choice that receives the test messages and notifies you via your mechanism of choice that it has successfully received a test message.
The Apache ActiveMQ broker supports discovery with IP multicast.
Applications can use discovery for JMS clients to auto-detect a Message Broker to connect to.
This could also be used to monitor a broker's status, using Java MultiCast support.
To invoke a piece of code when the broker is started, you can perhaps base it off either an embedded Camel route or broker interceptor. The idea being that when the broker is started, so will these components and thus allows them to issue whatever sort of notification you require.

jms Queue vs in memory java Queue

I have a situation where I need to read a(on going) messages from a topic and put them on another Queue . I have doubts do I need jms Queue or I can be satisfied with an in memory java Queue . I will do the reading from the Queue by other thread(s) in same jvm and will do client acknowledge of the message to the topic after reading the message from the (in memory) queue and process it as necessary (send it to remote IBM MQ) .So if my client crash the messages that were exist in the in memory queue will be lost but will still exist on topic and will be redeliver to me . Am I right ?
Some of this depends on how you have set up the queue/topic and the connection string you are using to read from IBM's MQ but if you are using the defaults you WILL lose messages if you're reading it to an in-memory queue.
I'd use ActiveMQ, either in the same JVM as a library so you have it taking care of receipt, delivery and persistence.
Also if you are listening to a topic you're not going to be sent missed messages after a crash even if you reconnect afterwards unless you've
configured your client as a durable subscriber
reconnect in the time (before the expireMessagesPeriod is reached)
The ActiveMQ library is not large and worth using if ensure delivery of every message is important, especially in an asynchronous environment.
Main difference is that in-memory loses data when the application goes down; JMS queue loses data when the server goes down IF the topic/queue is not persistent. The former is much more likely than the latter, so I'd also say go with JMS.

Store Weblogic JMS messages for analysis

We are currently having issues with Weblogic JMS, some of the messages received by the Tibco end are blank, but, our logs indicate that the messages are sent in full (we log just before sending it to the queue). We are planning to store the jms messages for a couple of days and verify if that is a problem at the Weblogic end or the tibco end.
I know that there is a persistance store in JMS, but that will clear the messages once the message is sent to the client. Do we have a feature that allows us to store the messages for a period of time?
Environment: Weblogic 8.1 Integration
Thanks.
When using JMS queues for messages, the message is meant for consumption by only 1 consumer. Once the message is consumed its removed from the JMS server for good.
I understand your requirement is to save the already delivered messages for reconciliation. This is not possible out of the box in WLS (for obvious reasons).
You have the following options
1) Enable JMS message logging, this will save all the messages that reach the server to be logged as a text xml in a log file.
2) Use QueueBrowser and read the messages and log it to where ever you want in what ever format you need.

Is it possible to look at received queue messages with the Tibco queue client?

We're using a Tibco client implementation of the JMS API. We have a MessageListener with an onMessage() implementation.
Is there a way with the Tibco client to inspect past (received) messages in the queue? (I realise this totally ignores the logical concept of a queue - I wondered if the queue implementation provided this workaround.)
No. Not for "past" messages.
Messages acknowledged by the receiver are removed from the queue - as their "function" is already done.
You could have a Listener configured to persist your messages in some DB or file - but for future messages.
A client uses a QueueBrowser object to look at messages on a queue without removing them.
#hawkeye Its not possible to browse messages from the past... At any point of time , you can browse destinations only for the pending messages.
There is no way for you browse all the received messages as EMS server usually deletes the message once it has delivered ( acknowledged) for the given delivery mode.
One possible way is to a send copy of the messages to another queue (without any receivers) before actually confirming the messages.
Also it depends on your acknowledgement mode and logic involved.

Categories