官术网_书友最值得收藏!

Request-response route sending a one-way message

When processing a message in a Request-Response (InOut) route, you sometimes need to send the message to an endpoint, but do not want to receive a response. This recipe shows you how to invoke such an endpoint using the InOnly MEP.

The MEP used can radically alter the behavior of an endpoint. For example, if you invoke a JMS endpoint within a request-response (InOut) route, it will send a message to a queue and set up a listener on a temporary destination waiting for a response; this is known as request-response over messaging. If the consumer of the message on the other side of the queue has not been written to send a response message, your route will wait indefinitely (or as long as the configurable timeout of the component).

This recipe shows how you can alter the MEP temporarily in order to send messages one way in a request-response route.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.changingmep package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with changingMep.

How to do it...

Use the inOnly DSL statement to explicitly route a message to that endpoint with that specific MEP:

In the XML DSL, this is written as:

<route>
  <from uri="direct:start"/>
 <inOnly uri="direct:oneWay"/>
  <transform>
    <constant>Done</constant>
  </transform>
</route>

Tip

The Endpoint invocation could also be written as:

<to uri="direct:oneWay" pattern="InOnly"/>

In the Java DSL, the same thing is expressed as:

from("direct:start")
 .inOnly("direct:oneWay")
  .transform().constant("Done");

Tip

The Endpoint invocation could also be written as:

to(ExchangePattern.InOnly, "direct:oneWay")

How it works...

When the message reaches the stage in the route that sends to the InOnly endpoint, the MEP associated with the exchange is temporarily changed to InOnly for the call to the specified endpoint and restored on completion of that call.

There is no need to copy the message as this DSL statement is just like a normal to statement sending the message to an endpoint; it just temporarily changes the MEP such that it does not wait for a response from that endpoint.

There's more...

The thread that processes the exchange through the main route is also used to process it through the producer endpoint (direct:oneWay). This makes this pattern very different to a Wire Tap, where we hand over the processing of the message to another thread.

See also

主站蜘蛛池模板: 富平县| 疏勒县| 林州市| 大厂| 依兰县| 许昌县| 东兴市| 曲松县| 栾城县| 双流县| 大方县| 宣汉县| 韶关市| 静海县| 托里县| 资兴市| 荣成市| 呼图壁县| 蒲江县| 陈巴尔虎旗| 抚顺市| 贵德县| 武穴市| 隆德县| 达孜县| 桐城市| 洛阳市| 民乐县| 原平市| 陆河县| 德昌县| 塘沽区| 民和| 炎陵县| 拉萨市| 柳林县| 方正县| 繁峙县| 唐山市| 滕州市| 宿迁市|