Simple example of MULE configuration RabbitMQ

environment Version
mule-standalone 3.9.0
anypoint-studio 6.4.0

MULE provides an AMQP Connector, so RabbitMQ can be configured with this Connector. Examples of AMQP can also be found in the Exchange in Anypoint-studio.
* (1) Download AMQP Connector and click to download . The current Connector version is 3.7.7, and you need to register an account to download. The downloaded zip package can be installed through Help->Install New Software of Anypoint-studio.
* (2) As mentioned above, the official sample . After opening the project through the Exchange of Anypoint-studio, and configure the project according to the sample document, configure RabbitMQ (configure an Exchange name salesexchange, configure a Queue name salesqueue, and then This Queue is bound in Exchange, and the above steps can be completed by RabbitMQ console). An error occurs when the project starts, and the main content of the error is as follows:

schema_reference.4: 无法读取方案文档 'http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd', 
原因为 1) 无法找到文档; 2) 无法读取文档; 3) 文档的根元素不是 <xsd:schema>

The error in the official example makes people speechless. The error clearly indicates that there is no mule-amqp.xsdsuch file. The access path is indeed 404. The foreign friend of Google answered that the maven dependency error or the jar package error was wrong. Try to add the project maven supportand add the maven dependency, but the error still occurs. . After repeated attempts, I thought it might be a problem with the xml configuration, so I recreated a Project and made an example exactly according to the official example. 需要注意:配置AMQP的时候,需要配置一个Connector Reference,不然会提示没有指定host, and finally start the project and run perfectly. According to the official example, http://localhost:{your_port}/send a json request, and finally get the sent information in the salesqueue queue of the RabbitMQ console. The example is now complete.

{
    "ITEMID": "001",
    "ITEMNAME": "Shirt",
    "QTY": 1,
    "PRICE": 20
}

Related screenshots:
Connector configuration diagram 1

Connector configuration diagram 2

RabbitMQ get message

Related reference content:
Answers from foreign friends


Simple example of sending and receiving messages

MULE FLOW PREVIEW
* Add a QUEUE of RabbitMQ, named test, other defaults.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:amqp="http://www.mulesoft.org/schema/mule/amqp" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/amqp http://www.mulesoft.org/schema/mule/amqp/current/mule-amqp.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <amqp:connector name="AMQP_0_9_Connector" validateConnections="true" doc:name="AMQP-0-9 Connector"/>
    <flow name="SendMessageToQueue">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" allowedMethods="POST" doc:name="HTTP"/>
        <amqp:outbound-endpoint queueName="test" queueDurable="true" responseTimeout="10000" connector-ref="AMQP_0_9_Connector" doc:name="AMQP-0-9"/>
        <set-payload value="#['Send Message']" doc:name="Set Payload"/>
    </flow>
    <flow name="GetMessageFromQueue">
        <amqp:inbound-endpoint queueName="test" queueDurable="true" responseTimeout="10000" exchange-pattern="request-response" connector-ref="AMQP_0_9_Connector" doc:name="AMQP-0-9"/>
        <byte-array-to-object-transformer doc:name="Byte Array to Object"/>
        <json:object-to-json-transformer doc:name="Object to JSON"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>

</mule>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326685075&siteId=291194637