Zhang Buzz
Zhang Buzz

Reputation: 11028

What is the correct endpoint of ObjectToJMSMessage?

I am new to Mule, and I really love the Anypoint Studio. I tried to put a message to ActiveMQ. I found that if I directly put JMS after string Payload, then it works, I can get the message in ActiveMQ. Like below:

enter image description here

But if I put an Object to JMSMessage transformer in it:

enter image description here

It keeps giving an error: java.lang.IllegalStateException: This transformer needs a valid endpoint. I almost tried all kinds of endpoint in, but no avail. I am wondering what should be the correct endpoint for the transformer?

The code is quite simple:

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

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 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.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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.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/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ" specification="1.1" password="admin" username="admin"/>
    <flow name="basic_tutorialFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <set-payload value="hello world" doc:name="Set Payload"/>
        <jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
        <jms:outbound-endpoint  connector-ref="Active_MQ" doc:name="JMS" topic="mytopic"/>
        <object-to-string-transformer doc:name="Object to String"/>
    </flow>
</mule>

Upvotes: 0

Views: 803

Answers (2)

aonthemoon
aonthemoon

Reputation: 50

You need to use the "Object to JMSMessage" transformer, and likewise "JMSMessage to Object" transformer, within the JMS component.

Example: I used the "Object to JMSMessage" transformer because I wanted my payload (java.util.Hashmap) to be transformed into a MapMessage, not a String. Intuitively, you should put the transformer before the JMS component.

In order to do this without getting the error java.lang.IllegalStateException: This transformer needs a valid endpoint, you have to find the Transformer settings within the JMS component, and add the transformer there.

So, for the JMS component that is writing messages to the queue, you add transformers to be referenced during Request: Transformer settings for JMS writing messages to the queue

When you click on the green plus-sign to add the transformer you want applied to the message before it's enqueued, you then select settings that show up when you use a normal transformer component within a Mulesoft flow.

Transformer Settings

In my example, I would enter in the Return Class as javax.jms.MapMessage.

Similarly, for a JMS component that's receiving messages from a JMS queue, you would add Transformers in the "Transformers Reference: Response" box, and put in the settings what class you would like the JMS message to be transformed into. This should work for any transformer that has "JMSMessage" in its name.

(Note: I am using Anypoint 6.6.3, Mule ESB 3.9.1, Mule 3, so this may not apply to Mule 4)

Upvotes: 0

rajeshkatram
rajeshkatram

Reputation: 26

JMS When used in between flow elements acts as outbound end point (if you observe your xml it already has it "jms:outbound-endpoint" .What is means is it takes a payload publishes it to the Queue or Topic that you have configured the JMS Endpoint to ) .

Typically in your scenario you don't need to have a transformer before the JMS outbound end point Mule implicitly transforms the message for you . And as a consequence you can create a new flow or an application that is reading this Queue/Topic which is a JMS Inbound Endpoint (jms:inbound-endpoint), depending where you place the JMS Component mule determines wether it is inbound or outbound).

With this what you are achieving is the reliability pattern . For which you can read more about it here .

https://docs.mulesoft.com/mule-user-guide/v/3.8/reliability-patterns

Upvotes: 1

Related Questions