IBM MQ Series reply message not immediately visible in reply queue - vb.net

I am building a tool that puts messages on a queue and put the response/reply on another (normally a stub queue)
All is working fine but it seems that the amount of time it takes for the reply message to be received and put the stub queue is longer than it really is. `
Try
PublicMQVariable.MQMessage_Reply = New MQMessage
PublicMQVariable.MQMessage_Reply.CorrelationId = PublicMQVariable.MQMessage_Request.MessageId
PublicMQVariable.MQMessage_Reply.MessageType = MQC.MQMT_REPLY
PublicMQVariable.MQGetMessageOptions_Response = New MQGetMessageOptions
PublicMQVariable.MQGetMessageOptions_Response.Options = MQC.MQGMO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING
PublicMQVariable.MQGetMessageOptions_Response.MatchOptions = MQC.MQMO_MATCH_CORREL_ID
PublicMQVariable.MQGetMessageOptions_Response.WaitInterval = PublicMQVariable.MyTimeOut
PublicMQVariable.MyStopwatch = Stopwatch.StartNew()
PublicMQVariable.MQQueue_Reply.Get(PublicMQVariable.MQMessage_Reply, PublicMQVariable.MQGetMessageOptions_Reply)
PublicMQVariable.MyStopwatch.Stop()
PublicMQVariable.MyReplyMessage = PublicMQVariable.MQMessage_Reply.ReadString(PublicMQVariable.MQMessage_Reply.MessageLength)
Catch ex As MQException
MsgBox("MQException: compCode: " & ex.CompCode.ToString() & " Reason: " + ex.Reason.ToString() & " - " & ex.Message)
MQDisconnectAndClose()
Return
End Try
The code above is just the part where the response is 'get'`
The Stopwatch says the reply is received in +/- 2000 milliseconds but when I browse the reply queue then the reply message is only present after about 18 seconds (looking at my watch and browsing the queue constantly)
This the use of the stopwatch accurate?
Why does it take so long for the message to be visible in the reply queue?
Is there away to capture the reply message as soon as it generated by the system? (before it is even put to the reply queue)

Are you using MQExplorer to browse the reply message? MQExplorer has a pre-defined refresh interval of 15 seconds. After every 15 seconds, MQExplorer refreshes the contents of the view. It will display the messages present in a queue, latest channel status etc.

Related

Get message count in ActiveMQ queue or receiver in c#

I'm at consumer end and reading message from a queue. How to get the count of the total messages in a queue (IDestination) and pass number of messages (let's say 100 messages) at a time to the receiver.
Please help to achieve it in c# .Net
One means of achieving this would be to enable the Statistics Broker Plugin and then send control commands to the broker from your C# client to obtain statistics on Queues you are interested in. The follow is a Java based example but you could produce something quite similar using Apache.NMS.ActiveMQ if that is what you are using for your C# client.
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue testQueue = session.createQueue("TEST.FOO");
MessageProducer producer = session.createProducer(null);
String queueName = "ActiveMQ.Statistics.Destination." + testQueue.getQueueName()
Queue query = session.createQueue(queueName);
Message msg = session.createMessage();
producer.send(testQueue, msg)
msg.setJMSReplyTo(replyTo);
producer.send(query, msg);
MapMessage reply = (MapMessage) consumer.receive();
assertNotNull(reply);
assertTrue(reply.getMapNames().hasMoreElements());
for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
String name = e.nextElement().toString();
System.err.println(name + "=" + reply.getObject(name));
}
That would allow you to see data such as:
memoryUsage=0
dequeueCount=0
inflightCount=0
messagesCached=0
averageEnqueueTime=0.0
destinationName=queue://TEST.FOO
size=1
memoryPercentUsage=0
producerCount=0
consumerCount=0
minEnqueueTime=0.0
maxEnqueueTime=0.0
dispatchCount=0
expiredCount=0
enqueueCount=1
memoryLimit=67108864

Bunny and RabbitMQ - Adapting the WorkQueue tutorial to cancel subscribing when the Queue is completely worked

I fill up my queue, check it has the right number of tasks to work and then have workers in parallell set to prefetch(1) to ensure each just takes one task at a time.
I want each worker to work its task, send a manual acknowledgement, and keep working taking from the queue if there is more work.
If there is not more work, i.e. the queue is empty, I want the worker script to finish up and return(0).
So, this is what I have now:
require 'bunny'
connection = Bunny.new("amqp://my_conn")
connection.start
channel = connection.create_channel
queue = channel.queue('my_queue_name')
channel.prefetch(1)
puts ' [*] Waiting for messages.'
begin
payload = 'init'
until queue.message_count == 0
puts "worker working queue length is #{queue.message_count}"
_delivery_info, _properties, payload = queue.pop
unless payload.nil?
puts " [x] Received #{payload}"
raise "payload invalid" unless payload[/cucumber/]
begin
do_stuff(payload)
rescue => e
puts "Error running #{payload}: #{e.backtrace.join('\n')}"
#failing stuff
end
end
puts " [x] Done with #{payload}"
end
puts "done with queue"
connection.close
exit(0)
ensure
connection.close
end
I want to still make sure I am done when the queue is empty. This is the example from the RabbitMQ site... https://www.rabbitmq.com/tutorials/tutorial-two-ruby.html . It has a number of things we want for our work queue, most importantly manual acknowledgements. But it does not stop running and I need that to happen programmatically when the queue is done:
#!/usr/bin/env ruby
require 'bunny'
connection = Bunny.new(automatically_recover: false)
connection.start
channel = connection.create_channel
queue = channel.queue('task_queue', durable: true)
channel.prefetch(1)
puts ' [*] Waiting for messages. To exit press CTRL+C'
begin
queue.subscribe(manual_ack: true, block: true) do |delivery_info, _properties, body|
puts " [x] Received '#{body}'"
# imitate some work
sleep body.count('.').to_i
puts ' [x] Done'
channel.ack(delivery_info.delivery_tag)
end
rescue Interrupt => _
connection.close
end
How can this script be adapted to exit out when the queue has been completely worked (0 total and 0 unacked)?
From what I understand, you want your subscriber to end if there are no pending messages in the RabbitMQ queue.
Given your second script, you could avoid passing block: true, and that will return nothing when there's no more data to process. In that case, you could exit the program.
You can see that in the documentation: http://rubybunny.info/articles/queues.html#blocking_or_nonblocking_behavior
By default it's non-blocking.

console log using selenium certain messages are getting truncated abruptly

I am trying to validate the browser console messages via selenium api certain messages are getting truncated abruptly and all these messages begin with some icon.
So for example expected messages is this “xyz-ENa50707a1661440e4a3070d8206797cf4.min.js?cb=1523503349:15 icon Rule "xyz" fired.” but what i am getting is "“xyz-ENa50707a1661440e4a3070d8206797cf4.min.js?cb=1523503349:15 icon".
my code is like
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
logEntries.getAll();
for (LogEntry entry : logEntries) {
System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
}
Any suggestion.
even System.setOut(printStream); not able capture full string in message.

vb.net connecting to MQ server

I migrated app from vb6 to vb.net, every thing is working fine except getting the message from the MQ server, when MQGet called, I get 2033 error (no Message)
also attached the capture message that sent to MQ from working vb6 and from not working vb.net, please help?enter image description here
'***********************************
'Send(MQPUT) to MQSeries and CICS
'***********************************
PutMsgOpts = MQPMO_DEFAULT
MsgDesc = MQMD_DEFAULT
MsgDesc.Persistence = MQPER_PERSISTENT
MsgDesc.MsgId = MQMI_NONE.Value
MsgDesc.CorrelId = "AMQ!NEW_SESSION_CORRELID" 'if using MQBridge
MsgDesc.ReplyToQ = gReplyToQ
MsgDesc.ReplyToQMgr = gMQRplyMgrName
MsgDesc.Format_Renamed = MQFMT_STRING
'sPutMsg is composed of 8 byte program name(host/cics)
' plus data desired to pass as string only (dfcommarea)
'************ MAX LENGTH IS 32776 *******************
sPutMsg = gCICSPrgName & gsHost_Msg
If Len(sPutMsg) <> 32768 Then
sPutMsg = sPutMsg & Space(32768 - Len(sPutMsg))
End If
sMsgIdGet.Value = MsgDesc.MsgId
'*******************************************
'MQClose the queue for request sent to host
'*******************************************
'HOST-BYPASS
MQCLOSE(Hconn, Hobj, MQCO_NONE, cC, Reason)
'HOST-BYPASS
'**********************************************************
'MQOpen the queue for receiving the request from the host
'**********************************************************
'set up the queue name
ObjDesc = MQOD_DEFAULT
ObjDesc.ObjectName = gReplyToQ
'Open
'HOST-BYPASS
MQOPEN(Hconn, ObjDesc, MQOO_INPUT_AS_Q_DEF Or MQOO_FAIL_IF_QUIESCING, Hobj, cC, Reason)
'HOST-BYPASS
'Hconn is set by MQseries in the Connect
'**************************************
'Receive (MQGET) from MQSeries and CICS
'**************************************
GetMsgOpts = MQGMO_DEFAULT
GetMsgOpts.Options = MQGMO_WAIT Or MQGMO_CONVERT
GetMsgOpts.WaitInterval = 10000 '20 seconds
MsgDesc = MQMD_DEFAULT
MsgDesc.Format_Renamed = MQFMT_STRING
MsgDesc.Persistence = MQPER_PERSISTENT
MsgDesc.CorrelId = sMsgIdGet.Value 'set correlId with MQGET msgid returned
MsgDesc.MsgId = MQMI_NONE.Value
MsgDesc.ReplyToQ = gReplyToQ
MsgDesc.ReplyToQMgr = gMQRplyMgrName
'** sGetMsg is composed of 8 byte program name(host/cics)
'** plus data desired to pass as string only (dfcommarea)
'************ MAX LENGTH IS 32776 *******************
sGetMsg = New String(" ", 32768)
'Command to receive from to MQSeries and CICS
retryCount = 0
cC = MQCC_OK + 1
Reason = 2033
Do While cC <> MQCC_OK And Reason = 2033
MQGET(Hconn, Hobj, MsgDesc, GetMsgOpts, Len(sGetMsg), sGetMsg, readlen, cC, Reason)
retryCount = retryCount + 1
If retryCount > 1 Then Exit Do
Loop
'************************
'MQClose queue for input
'************************
MQCLOSE(Hconn, Hobj, MQCO_NONE, cC, Reason)
If you get 2033, then you know the queue is there, but the message you are trying to retrieve is not. Use MQ Explorer or plain MQ samples along with runmqsc to check if there are any messages on that queue, and if there are, if their correlation id matches what your program is supplying.
If there are no messages there, then check that your messages have been indeed received by the CICS program your are sending them to, and if that program responded.
A 2033 problem may be your coding problem, but more probably it's something in the configuration and setup that has changed along with your conversion. You may have a differently configured queue manager, with differently configured channels etc. Check the entire chain.

pika dropping basic_publish messages sporadically

I'm trying to publish messages with pika, using Celery tasks.
from celery import shared_task
from django.conf import settings
import json
#shared_task
def publish_message():
params = pika.URLParameters(settings.BROKER_URL + '?' + 'socket_timeout=10&' + 'connection_attempts=2')
conn = pika.BlockingConnection(parameters=params)
channel = conn.channel()
channel.exchange_declare(
exchange = 'foo',
type='topic'
)
channel.tx_select()
channel.basic_publish(
exchange = 'foo',
routing_key = 'bar',
body = json.dumps({'foo':'bar'}),
properties = pika.BasicProperties(content_type='application/json')
)
channel.tx_commit()
conn.close()
This task is called from the views.
Due to some weird reason, sometimes randomly, the messages are not getting queued. In my case, every second message is getting dropped. What am I missing here?
I would recommend that you enable confirm_delivery in pika. This will ensure that messages get delivered properly, and if for some reason the message could not be delivered. Pika will fail with either an exception, or return False.
channel.confirm_delivery()
successful = channel.basic_publish(...)
If the process fails you can try to send the message again, or log the error message from the exception so that you can act accordingly.
Try this:
chanel = conn.channel()
try:
chanel.queue_declare(queue='foo')
except:
pass
chanel.basic_publish(
exchange='',
routing_key='foo',
body=json.dumps({'foo':'bar'})
)