Permalink
Browse files

add a Rendezvous example

  • Loading branch information...
1 parent ece4ae5 commit 1e3bd1120ee0644c3d9fb859576289297ed74fe7 @felipeg48 committed Feb 19, 2013
@@ -28,7 +28,11 @@
</int:channel>
<!-- rendezvousChannelTest -->
+ <int:channel id="replyChannel">
+ <int:queue capacity="10" />
+ </int:channel>
<int:channel id="rendezvousChannel">
<int:rendezvous-queue/>
</int:channel>
+
</beans>
@@ -14,6 +14,7 @@ import org.springframework.integration.MessageChannel
import org.springframework.integration.MessageHeaders
import org.springframework.integration.channel.PublishSubscribeChannel
import org.springframework.integration.channel.QueueChannel
+import org.springframework.integration.channel.RendezvousChannel
import org.springframework.integration.core.MessageHandler
import org.springframework.integration.message.GenericMessage
import org.springframework.integration.support.MessageBuilder
@@ -40,6 +41,12 @@ class ChannelTest {
@Autowired
MessageChannel priorityWithComparatorChannel
+ @Autowired
+ MessageChannel rendezvousChannel
+
+ @Autowired
+ MessageChannel replyChannel
+
@Test
@Ignore
void p2pChannelTest() {
@@ -152,8 +159,37 @@ class ChannelTest {
}
@Test
- @Ignore
void rendezvousChannelTest(){
+ //Step 0. Some variables
+ def replyMessage = "Got it"
+ //Producer
+ //Step 1. Build the message and send it
+ Thread.start {
+ println "Producer: Sending Message and waiting for reply"
+ def msg = MessageBuilder
+ .withPayload("A rendezvous message")
+ .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build()
+ assertNotNull msg
+ rendezvousChannel.send msg,10000
+
+ Message rp = ((QueueChannel) replyChannel).receive(10000)
+ assertNotNull rp
+ println "Producer: Consumer reply > ${rp.payload}"
+ assertEquals replyMessage,rp.payload
+ }
+ //Consumer
+ //Step 2. Received the message and identify if it needs reply
+ Message message = ((RendezvousChannel) rendezvousChannel).receive(10000)
+ assertNotNull message
+ println "Consumer: $message"
+
+ //Step 2.1. Get the reply channel
+ def reply = message.getHeaders().get(MessageHeaders.REPLY_CHANNEL)
+ assertNotNull reply
+
+ //Step 2.2. Send a Reply to it
+ Message<String> gotit = new GenericMessage<String>(replyMessage)
+ reply.send gotit
}
}

0 comments on commit 1e3bd11

Please sign in to comment.