【问题标题】:What is the correct endpoint of ObjectToJMSMessage?ObjectToJMSMessage 的正确端点是什么?
【发布时间】:2017-12-13 03:45:20
【问题描述】:

我是 Mule 的新手,我真的很喜欢 Anypoint Studio。我试图向 ActiveMQ 发送消息。我发现如果我在字符串Payload之后直接放JMS,那么它可以工作,我可以在ActiveMQ中获取消息。如下:

但是如果我在其中放入一个 Object to JMSMessage 转换器:

它一直报错:java.lang.IllegalStateException: This transformer needs a valid endpoint。我几乎尝试了各种端点,但无济于事。我想知道变压器的正确端点应该是什么?

代码很简单:

<?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>

【问题讨论】:

    标签: jms mule


    【解决方案1】:

    JMS 当在流元素之间使用时充当出站端点(如果您观察您的 xml,它已经有它“jms:outbound-endpoint”。这意味着它需要一个有效负载发布它到您已将 JMS 端点配置到的队列或主题)。

    通常在您的场景中,在 JMS 出站端点 Mule 为您隐式转换消息之前,您不需要转换器。因此,您可以创建一个新流或一个正在读取此队列/主题的应用程序,该队列/主题是一个 JMS 入站端点 (jms:inbound-endpoint),具体取决于您放置 JMS 组件 mule 确定的位置无论是入站还是出站)。

    有了这个,你实现的是可靠性模式。您可以在此处阅读更多相关信息。

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

    【讨论】:

    • 谢谢!我想知道什么时候应该使用这个“Object to JMSMessage”转换器?如果我使用它,它的端点可能是什么组件?
    【解决方案2】:

    您需要在 JMS 组件中使用“Object to JMSMessage”转换器,以及“JMSMessage to Object”转换器。

    示例:我使用“Object to JMSMessage”转换器,因为我希望将有效负载 (java.util.Hashmap) 转换为 MapMessage,而不是 String。直观地说,您应该将转换器放在 JMS 组件之前。

    为了在不出现错误java.lang.IllegalStateException: This transformer needs a valid endpoint 的情况下执行此操作,您必须在 JMS 组件中找到 Transformer 设置,并在那里添加转换器。

    因此,对于将消息写入队列的 JMS 组件,您可以添加要在请求期间引用的转换器:

    当您单击绿色加号以在消息入队之前添加要应用于消息的转换器时,您可以选择在 Mulesoft 流程中使用普通转换器组件时显示的设置。

    在我的示例中,我将在 Return Class 中输入 javax.jms.MapMessage

    类似地,对于从 JMS 队列接收消息的 JMS 组件,您可以在“Transformers Reference: Response”框中添加 Transformers,并在设置中输入您希望 JMS 消息转换成的类。这应该适用于任何名称中包含“JMSMessage”的转换器。

    (注意:我使用的是 Anypoint 6.6.3、Mule ESB 3.9.1、Mule 3,所以这可能不适用于 Mule 4)

    【讨论】:

      猜你喜欢
      • 2019-12-12
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-05
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多