日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Request-reply messaging

發(fā)布時(shí)間:2024/4/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Request-reply messaging 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

JMS messaging with Camel (and in general) is asynchronous by default. Messages are

sent to a destination, and the client doesn’t wait for a reply. But there are times when

it’s useful to be able to wait and get a reply after sending to a destination. One obvious

application is when the JMS destination is a frontend to a service—in this case, a client

sending to the destination would be expecting a reply from the service.

JMS supports this type of messaging by providing a JMSReplyTo header, so that the

receiver knows where to send the reply,

and a JMSCorrelationID, used to match

replies to requests if there are multiple

replies awaiting. This flow of messages is

illustrated in figure 7.5.

Camel takes care of this style of messaging,

so you don’t have to create special

reply queues, correlate reply

messages, and the like. By changing the

message exchange pattern (MEP) to

InOut, Camel will enable request-reply

mode for JMS.

To demonstrate, let’s take a look at an order validation service within Rider Auto

Parts’ backend systems that checks orders against the company database to make sure

the parts listed are actual products. This service is exposed via a queue named validate.

The route exposing this service over JMS could be as simple as this:

from("jms:validate").bean(ValidatorBean.class);

?

When calling this service, you just need to tell Camel to use request-reply messaging by

setting the MEP to InOut. You can use the exchangePattern option to set this as follows:

from("jms:incomingOrders").to("jms:validate?exchangePattern=InOut")...

You can also specify the MEP using the inOut DSL method:

from("jms:incomingOrders").inOut().to("jms:validate")...

With the inOut method, you can even pass in an endpoint URI as an argument, which

shortens your route:

from("jms:incomingOrders").inOut("jms:validate")...

By specifying an InOut MEP, Camel will send the message to the validate queue and

wait for a reply on a temporary queue that it creates automatically. When the ValidatorBean

returns a result that message is propagated back to the temporary reply

queue, and the route continues on from there.

Rather than using temporary queues, you can also explicitly specify a reply queue.

This can be done by setting the JMSReplyTo header on the message or by using the

replyTo URI option described in table 7.5.

A handy way of calling an endpoint that can return a response is by using the

request methods of the ProducerTemplate. For example, you can send a message into

the incomingOrders queue and get a response back with the following call:

Object result = template.requestBody("jms:incomingOrders",

"<order name=\"motor\" amount=\"1\" customer=\"honda\"/>");

This will return the result of the ValidatorBean.

To try this out for yourself, go to the chapter7/jms directory in the book’s source,

and run this command:

mvn test -Dtest=RequestReplyJmsTest

The command will run a unit test demonstrating request-reply messaging as we’ve discussed

in this section.

In the JMS examples we’ve looked at so far, several data mappings have been happening

behind the scenes—mappings that are necessary to conform to the JMS specification.

Camel could be transporting any type of data, so that data needs to be

converted to a type that JMS supports. We’ll look into this next.

總結(jié)

以上是生活随笔為你收集整理的Request-reply messaging的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。