Creating WebMQ Synchronous

I am trying to get WebMQ to act synchronously in MULE in order to turn the message queue into a REST api for an internal project. Unfortunately, I know very little about MULE.

After good work, I began to understand the Request-Reply area and tried to use the WMQ connector with it, only to find out what WMQ sends only after the stream has ended.

I tried to put the request in another thread using the VM to invoke it.

but so far this simply leads to the fact that he always waits on WMQ, which will never happen.

I also tried using virtual machines for round trip:

But he seems to be doing the same thing as without, where he simply ignores the entry.

Now I know that input and output for WMQ work, as I previously set up the stream, which used http to communicate with itself and let it know when the message passed.

Essentially I want, but using HTTP instead of AJAX

My last, and perhaps the closest attempt, looks like this:

XML:

<?xml version="1.0" encoding="UTF-8"?> <mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:http="http://www.mulesoft.org/schema/mule/http" version="EE-3.6.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio" xmlns:test="http://www.mulesoft.org/schema/mule/test" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd http://www.mulesoft.org/schema/mule/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd"> <wmq:connector channel="MAGENTO.SVRCONN" doc:name="WMQ Connector" hostName="[ip]" name="wmqConnector" port="1414" queueManager="MAGENTO" transportType="CLIENT_MQ_TCPIP" validateConnections="true" /> <vm:connector name="VM" validateConnections="true" doc:name="VM"> <vm:queue-profile maxOutstandingMessages="500"> <default-persistent-queue-store/> </vm:queue-profile> </vm:connector> <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/> <flow name="Input"> <http:listener config-ref="HTTP_Listener_Configuration" path="/mq" doc:name="HTTP"/> <set-payload value="#[message.inboundProperties.'http.query.params'.xml]" doc:name="Set Payload"/> <logger message="Entering Request-Reply Payload: #[payload]" level="INFO" doc:name="Logger"/> <request-reply doc:name="Request-Reply"> <vm:outbound-endpoint exchange-pattern="one-way" path="mq" connector-ref="VM" doc:name="VM_TriggerSend" /> <vm:inbound-endpoint exchange-pattern="request-response" path="mq-return" connector-ref="VM" doc:name="VM_Receive" /> </request-reply> <logger message="Request-Reply has ended. Payload: #[payload]" level="INFO" doc:name="Logger"/> </flow> <flow name="Send_Message"> <vm:inbound-endpoint exchange-pattern="one-way" path="mq" connector-ref="VM" doc:name="VM_Send"/> <logger message="(Preparing to Dispatch) Payload: #[payload]" level="INFO" doc:name="Logger"/> <wmq:outbound-endpoint queue="PUT_QUEUE" connector-ref="wmqConnector" doc:name="WMQ"/> <logger message="Message presumably being dispatched after this log" level="INFO" doc:name="Logger"/> </flow> <flow name="Receive_Message"> <wmq:inbound-endpoint queue="GET_QUEUE" connector-ref="wmqConnector" doc:name="WMQ_Receive" /> <logger message="Triggering Receive" level="INFO" doc:name="Logger"/> <vm:outbound-endpoint exchange-pattern="request-response" path="mq-return" connector-ref="VM" doc:name="VM_TriggerReceive" /> </flow> </mule> 

Which almost works, but it hangs endlessly without sending a response to the HTTP server. Setting vm: the inbound-end point in the Request-Reply stream unilaterally does not allow it to hang, but does not send the new payload that was received, but instead the previous payload (as if it were skipped).

Any help at all would be greatly appreciated!

+6
source share
2 answers

If I understand correctly, you are simply trying to expose the request in the queue and the response in the well-known queue as the REST api.

There is no need for VM queues, and none of the request-response elements as a JMS transport can mimic the template for exchanging responses to a request.

JMS queues are one way. You need to answer another queue. The request-response script logic is an outbound endpoint that has an outbound property: MULE_REPLYTO . This property should be set with the name of your well-known response to the queue: GET_QUEUE (if no such header is provided, a temporary queue is created).

The MULE_REPLY header will become the standard JMSReplyTo when mesasge is received in the service. The service must authenticate this header, sending the response back to this queue. If the service is implemented in Mule, this will happen automatically, otherwise it may not happen. You must verify compliance.

If you want to use the request-request area with one-way endpoints, and not with one request endpoint, this is normal, it should work the same, but with a lot of code.

+2
source

Creating an Asynchronous Data Source Synchronous can really be complicated. But I do not see a problem with your request-response strategy.

Try using a request-response with a WMQ endpoint on both sides. Then keep an eye on the queues and make sure the message and response are doing as they should. Do you use the same queue for request and response? The simplest scenario is to use different ones, is it possible for your use case?

-1
source

Source: https://habr.com/ru/post/989223/


All Articles