【问题标题】:Posting to a REST endpoint from a vm queue in Mule从 Mule 中的 vm 队列发布到 REST 端点
【发布时间】:2023-10-20 23:54:01
【问题描述】:

我有一个 mule 流,它接受一个 xml 并将其发布到一个 vm 队列,名称为 mule 中的“mailQueue”。 xml输入和mule流程如下:

<Mail>
  <Name>JonHender</Name>
  <Age>16</Age>
</Mail>

Mule_config.xml:

 <!-- This is the persistent VM connector -->
           <vm:connector name="mailQueueConnector" queueTimeout="1000">
                 <vm:queue-profile>
                <file-queue-store />
                 </vm:queue-profile>
           </vm:connector>


            <flow name="MailService">
                <https:inbound-endpoint address="https://localhost:71234/message/email"
                    method="POST"
                    exchange-pattern="request-response"
                    contentType="application/xml"/>

                <vm:outbound-endpoint path="mailQueue" connector-ref="mailQueueConnector">
                    <message-property-filter pattern="http.status=200" />
                    <logger message="INTO mailQueue" level="INFO"/>
                </vm:outbound-endpoint>

            </flow>

现在,我必须读取此“mailQueue”并将其发布到 REST 端点 (https://localhost:71234/messages/sendemail)。我尝试在同一流程中添加它,但没有用

<inbound>
    <vm:inbound-endpoint address="vm://emailBufferQueue" exchange-pattern="one-way" connector-ref="emailQueueConnector" />
</inbound>
<outbound>
    <https:outbound-endpoint address="https://localhost:71234/messages/sendemail"
</outbound>

如何从 vm 队列中读取数据并将其发布到 REST 端点?我可以在我写入队列的同一流程中执行此操作,还是应该创建一个新流程?有人可以向我展示从 the 读取并将其发送到 Rest 端点的流程吗?

提前谢谢大家,圣诞快乐

【问题讨论】:

  • 嘿大卫...我不完全熟悉这个论坛的规则。这是我的错,下次会记住的。感谢您指出这一点

标签: java rest jakarta-ee esb mule


【解决方案1】:

在另一个流程中使用mailQueue

<flow name="MailSender">
    <vm:inbound-endpoint path="mailQueue"
                         exchange-pattern="one-way"
                         connector-ref="mailQueueConnector" />
    <https:outbound-endpoint
           address="https://#[message.inboundProperties.username]:#[message.inboundProperties.password]@localhost:71234/messages/sendemail" />
</flow>

【讨论】:

  • 顺便说一句,我昨天开始读你的“mule in action”一书。到目前为止很棒的书......关于是否有任何更新版本即将发布的任何想法?
  • 谢谢。我希望你买了第二版(包括 Mule 3):manning.com/dossot2 我们每个月左右都会有新的章节。
  • 在将“mailQueue”中的消息发布到 REST 端点时,我得到了这个异常。注册的身份验证设置为 org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter 但那里会话中没有安全上下文。端点 localhost:71234/v1 上的身份验证被拒绝。消息负载类型:ContentLengthInputStream (org.mule.api.security.UnauthorisedException) org.mule.transport.http.filters.HttpBasicAuthenticationFilter:160 (mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/…)
  • 如何将 Rest 端点所需的身份验证详细信息传递给队列中的消息?
  • 作为消息属性 - 然后在出站端点 URL 中使用这些属性来验证调用。