How to understand the “synchronous” and “asynchronouns” messaging in JMS?

前端 未结 4 1848
温柔的废话
温柔的废话 2020-12-24 02:18

After reading some document of JMS, I totally puzzled by the phrase synchronous and asynchronouns.

See this page: http://docs.oracle.com/cd

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 03:06

    I understand synchronous/asynchronous differently.

    Synchronous: Caller(Sender) has to wait till the response from consumer has been received(till the time-out) -- request/reply pattern

    Asynchronous: Caller(Sender) just post message and continue with its work, while the consumer processes as soon as the message reaches it -- one way request

    Any MOM(Message Oriented Middle ware) follows service activator pattern which promotes asynchronous communication. One of my project has implemented a framework around JMS to make communication really synchronous.

    1. Any message has 2 parts. a. Metadata attributes b. Payload
    2. Set attribute "reply-to-queue" to a randomly generated value
    3. Make sure the MOM framework creates temporary queue with name from #2
    4. Make sure the sender spawns thread, which listens to temporary queue created in #3
    5. Publish message and block sender till it receives message to temporary queue
    6. Make sure the consumer intercepts "reply-to-queue" header and publishes response to it

    This is one of the ways to make MOM based communication acts like synchronous. You may find other implementations like request-reply mechanism.

提交回复
热议问题