How to get LockToken of new BrokeredMessage added Azure Service Bus Queue - azure-servicebus-queues

After sending the BrokeredMessage to the queue, like below
BrokeredMessage msg = new BrokeredMessage(content);
client.Send(msg);
Is there any way to get the value of this msg.LockToken?

You can get LockToken from Message.SystemProperties.LockToken.

Related

How to force delete Queue on Qmanager with PCF commands

Currently I use PCF command to delete a Queue on QMANAGER with
PCFMessage message = new PCFMessage( CMQCFC.MQCMD_DELETE_Q );
message.addParameter( CMQC.MQCA_Q_NAME, name);
agent.send( message );
Could I force delete if queue is occupied?
I have tried without succes on QL
#Override
protected PCFMessage getRequestRemove(String objetName,
String qmanagerName,boolean forceQmanager) {
PCFMessage request = new PCFMessage(CMQCFC.MQCMD_DELETE_Q);
request.addParameter( CMQCFC.MQIACF_PURGE, CMQCFC.MQPO_YES );
request.addParameter(CMQC.MQCA_Q_NAME, objetName);
request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
return request;
}
Error code is Caused by: com.ibm.mq.pcf.PCFException: MQJE001: Code achèvement '2', Motif '3014'.
My PCF library is 7.1.0.4
regards
There is no FORCE option on a DELETE queue command. If the queue is currently open by an application for input and they are waiting in an MQGET you can kick them out with the following command.
MQSC
ALTER QLOCAL(q-name) GET(DISABLED)
PCF
PCFMessage message = new PCFMessage (CMQCFC.MQCMD_CHANGE_Q);
message.addParameter(CMQC.MQCA_Q_NAME, name);
message.addParameter(CMQC.MQIA_INHIBIT_GET, CMQC.MQQA_GET_INHIBITED);
agent.send(message);
However if the queue is currently open and the application is not currently in either an MQGET or an MQPUT, then you cannot kick them out in this way, your only option then is to find the application in question using DISPLAY CONN, and then issue a STOP CONN to get them to release the queue.
The mostly likely occupation of a queue is the long MQGET-waiter, and so the above example command will help for most cases.
Morag's answer addresses possible ways to disconnect processes that currently have the queue open, if you also want to remove the queue when messages are on the queue you would need to ask MQ to PURGE the messages:
PCFMessage message = new PCFMessage( CMQCFC.MQCMD_DELETE_Q );
message.addParameter( CMQC.MQCA_Q_NAME, name);
message.addParameter( CMQCFC.MQIACF_PURGE, CMQCFC.MQPO_YES );
agent.send( message );

Receive method in JMS waiting for messages

I want a method to browse all messages from a messsage queue and can send it to another queue using jmstemplate with using Websphere queues(NOT MQ). I have tried using receive and it is able to retrieve all the messages from the queue but it is still waiting for another message. And the messages are being lost. It must be in a transaction
The Code I have Tried:
**String message = (String) jmsTemplate.receiveAndConvert();
System.out.print(message);
while ((message = (String) jmsTemplate.receiveAndConvert()) != null) {
messages.add(message);
}
return messages;
}**
The JMStemplate should be used for only synchronous read or sending message. For asychronous read use one of the listener implementation. Read here

Request-response pattern using Spring amqp library

everyone. I have an HTTP API for posting messages in a RabbitMQ broker and I need to implement the request-response pattern in order to receive the responses from the server. So I am something like a bridge between the clients and the server. I push the messages to the broker with specific routing-key and there is a Consumer for that messages, which is publishing back massages as response and my API must consume the response for every request. So the diagram is something like this:
So what I do is the following- For every HTTP session I create a temporary responseQueue(which is bound to the default exchange, with routing key the name of that queue), after that I set the replyTo header of the message to be the name of the response queue(where I will wait for the response) and also set the template replyQueue to that queue. Here is my code:
public void sendMessage(AbstractEvent objectToSend, final String routingKey) {
final Queue responseQueue = rabbitAdmin.declareQueue();
byte[] messageAsBytes = null;
try {
messageAsBytes = new ObjectMapper().writeValueAsBytes(objectToSend);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
MessageProperties properties = new MessageProperties();
properties.setHeader("ContentType", MessageBodyFormat.JSON);
properties.setReplyTo(responseQueue.getName());
requestTemplate.setReplyQueue(responseQueue);
Message message = new Message(messageAsBytes, properties);
Message receivedMessage = (Message)requestTemplate.convertSendAndReceive(routingKey, message);
}
So what is the problem: The message is sent, after that it is consumed by the Consumer and its response is correctly sent to the right queue, but for some reason it is not taken back in the convertSendAndReceived method and after the set timeout my receivedMessage is null. So I tried to do several things- I started to inspect the spring code(by the way it's a real nightmare to do that) and saw that is I don't declare the response queue it creates a temporal for me, and the replyTo header is set to the name of the queue(the same what I do). The result was the same- the receivedMessage is still null. After that I decided to use another template which uses the default exchange, because the responseQueue is bound to that exchange:
requestTemplate.send(routingKey, message);
Message receivedMessage = receivingTemplate.receive(responseQueue.getName());
The result was the same- the responseMessage is still null.
The versions of the amqp and rabbit are respectively 1.2.1 and 1.2.0. So I am sure that I miss something, but I don't know what is it, so if someone can help me I would be extremely grateful.
1> It's strange that RabbitTemplate uses doSendAndReceiveWithFixed if you provide the requestTemplate.setReplyQueue(responseQueue). Looks like it is false in your explanation.
2> To make it worked with fixed ReplyQueue you should configure a reply ListenerContainer:
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(rabbitConnectionFactory);
container.setQueues(responseQueue);
container.setMessageListener(requestTemplate);
3> But the most important part here is around correlation. The RabbitTemplate.sendAndReceive populates correlationId message property, but the consumer side has to get deal with it, too: it's not enough just to send reply to the responseQueue, the reply message should has the same correlationId property. See here: how to send response from consumer to producer to the particular request using Spring AMQP?
BTW there is no reason to populate the Message manually: You can just simply support Jackson2JsonMessageConverter to the RabbitTemplate and it will convert your objectToSend to the JSON bytes automatically with appropriate headers.

Creating a listener in TIBCO Rendezvous

I'm trying to create a listener in tibco rendezvous. I want to listen in on a particular subject. I'm aware that its supposed to look something like this:
TibrvListener(
TibrvQueue queue,
TibrvMsgCallback callback,
TibrvTransport transport,
java.lang.String subject,
java.lang.Object closure)
throws TibrvException
I have this code. However, I don't know a couple of things. How do I create a TibrvMsgCallback object? How do I pass in the transport? I have a publisher that sends the message as a seperate program. Do I recreate an identical transport in my subscribe program?
queue = new TibrvQueue();
dispatcher = new TibrvDispatcher(queue);
queue.setName(key);
this.listener = new TibrvListener(queue, null, null, subject, null);
TibrvTransport message = this.listener.getTransport();
You first open the Tibrv
Tibrv.open(Tibrv.IMPL_NATIVE);
Create transport
TibrvTransport transport = new TibrvRvdTransport(service, network, daemon);
Create Listener
new TibrvListener(Tibrv.defaultQueue(), this, transport, subject, null);
If your listener is "this", your class needs to implement TibrvMsgCallback
Messages can be processed on arrival in the onMsg(TibrvListener listener, TibrvMsg msg) method.

How to using amq.topic to pub/sub messages in Apache Qpid

I have a C++ publisher to send messages like this:
Connection connection;
connection.open("127.0.0.1", 5672);
Session session = connection.createSession();
Message msg;
msg.setData("TestAMsg");
msg.getDeliveryProperties().setRoutingKey("test.A");
session.messageTransfer(arg::content = message,
arg::destination = "amq.topic");
msg.setData("TestBMsg");
msg.getDeliveryProperties().setRoutingKey("test.B");
session.messageTransfer(arg::content = message,
arg::destination = "amq.topic");
And I have a Java subscriber like this:
AMQConnectionFactory connectionFactory = new
AMQConnectionFactory("amqp://guest:guest#myhost/test?
brokerlist='tcp://127.0.0.1:5672'");
AMQConnection connection = (AMQConnection)
connectionFactory.createConnection();
org.apache.qpid.jms.Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
AMQTopic destination = (AMQTopic)
AMQDestination.createDestination("topic://amq.topic//exclusive='false'?
bindingkey='Test.A'");
MessageConsumer messageAConsumer = session.createConsumer(destination);
Message message_ = messageConsumer_.receive();
No messages received in above code. I am very confused how this will work? What is the right form of bingding URL for consumers? What am I missing?
Your consumer specifies a binding key that is different than the routing key used by the producer.
Your producer code:
msg.getDeliveryProperties().setRoutingKey("test.A");
Your consumer code:
AMQTopic destination = (AMQTopic)
AMQDestination.createDestination("topic://amq.topic//exclusive='false'?
bindingkey='Test.A'");
Notice the difference in case for the first character of each key. Your producer uses test.A and your consumer uses Test.A, and since the keys are case-sensitive they are considered completely different. That's why your producer won't get any messages.
your binding key should be test.# or test.*
the differencees between # and *, follow this link http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/2/html/Messaging_User_Guide/chap-Messaging_User_Guide-Exchanges.html#sect-Messaging_User_Guide-Exchange_Types-Topic_Exchange

Resources