Simultanous sending and receiving

狂风中的少年 提交于 2019-12-14 03:04:14

问题


I am trying to send and receive message to and from JMS topics.

<testcase name="DeliveryToPT3PLIT">
        ...
        <actions>
            ...              
            <send endpoint="fromEndpoint">
                <message>
                    <resource file="com/roche/icc/citrus/messages/input/PT-3PLWoBatchSplit.xml"/>
                </message>
                <header>
                    ...
                </header>
            </send>

            <receive endpoint="toEndpoint">
                <description>Receive asynchronous message from topic</description>
                <message>
                        <resource file="com/roche/icc/citrus/messages/output/PT-3PLWoBatchSplit.xml"/>
                </message>
                <header>
                    ...
                </header>
            </receive>
        </actions>
    </testcase>

It seems that these operations go one after another. The problem is that my application works really fast and when I send a message to first topic it appears on "toEndpoint" almost immediately. So the receive operation does not manage to catch appropriate message since it has been already processed.

Is there any way to make this operations simultaneously?

Regards


回答1:


There is one thing to note about using JMS topics, because they work in a publish/subscribe manner, you have to subscribe first in order to receive the message.

That means you need to subscribe to the topic before a message is going to be published. Also, if you say that your application is fast, you may need to wait a few millis before sending the message. Here is a Java DSL example of what I think may work for you. (Note: I have tested this example with a JMS topic)

parallel().actions(
    sequential().actions( // Thread #1
            ...
            receive(action -> action.endpoint(toEndpoint).payload("message to be received"))),
    sequential().actions( // Thread #2
            sleep(500),
            send(action -> action.endpoint(fromEndpoint).payload("message to be sent"))));

Notice the parallel() action container. It will execute every action inside it in a separate thread. Each sequential() represents a series of actions that allows you to group them together. Because both sequential() containers are inside the parallel(), the actions inside each of them will be executed on different threads.

So what happens here: you split your actions on two threads. On the first thread you wait for a message. On the second thread, you make it sleep for 500 millis first, after which you send the message.

I'm sorry that I don't have an XML example, but I hope this helps anyway.

Also don't forget to set the pub-sub-domain property to true on your endpoints. See the Citrus documentation on JMS topics: here.



来源:https://stackoverflow.com/questions/48005813/simultanous-sending-and-receiving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!