Point to Point Communication achieved
I've managed to hook up some working point-to-point communication now that I realized that channels are directional.
For each request/response I would need two queues and four channels set up, and while the xml is straightforward to set up doing this for tons of different requests will be error prone, so I am trying to wrap up this set up into a Proxy class and a Stub class.
Code:
<channel id="statusRequestProducerChannel"/>
<jms-target connection-factory="connectionFactory" destination="statusRequestQueue" channel="statusRequestProducerChannel"/>
<beans:bean id="statusRequestQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg><beans:value>statusRequest.que</beans:value></beans:constructor-arg>
</beans:bean>
<channel id="statusRequestConsumerChannel"/>
<jms-source connection-factory="connectionFactory" destination="statusRequestQueue" channel="statusRequestConsumerChannel"/>
<endpoint input-channel="statusRequestConsumerChannel" handler-ref="statusResponder">
<concurrency core="1" max="1" queue-capacity="1" keep-alive="10" />
</endpoint>
<beans:bean id="statusResponder"
class="nz.co.bonusbonds.bbo.stub.manager.StatusResponder">
</beans:bean>
<channel id="statusResponseProducerChannel"/>
<jms-target connection-factory="connectionFactory" destination="statusResponseQueue" channel="statusResponseProducerChannel"/>
<beans:bean id="statusResponseQueue" class="org.apache.activemq.command.ActiveMQQueue">
<beans:constructor-arg><beans:value>statusResponse.que</beans:value></beans:constructor-arg>
</beans:bean>
<channel id="statusResponseConsumerChannel"/>
<jms-source connection-factory="connectionFactory" destination="statusResponseQueue" channel="statusResponseConsumerChannel"/>
I can see how most of the spring hookup results in java code but am not sure how the MessageChannel gets created, or how the jms-target and channel get linked (i.e. in the code below the new MessageChannel() does not compile because MessageChannel is an interface, and target.setChannel(input); does not compile because there is no such method, and none seems to exist in the other direction either (i.e. input.setTarget(target)))
Code:
@Override
protected MessageChannel getInputChannel() {
// <channel id="statusRequestProducerChannel"/>
MessageChannel input=new MessageChannel();
//<beans:bean id="statusRequestQueue" class="org.apache.activemq.command.ActiveMQQueue">
// <beans:constructor-arg><beans:value>statusRequest.que</beans:value></beans:constructor-arg>
//</beans:bean>
Destination destination=new ActiveMQQueue(getRequestQueueName());
// <jms-target connection-factory="connectionFactory" destination="statusRequestQueue" channel="statusRequestProducerChannel"/>
JmsTargetAdapter target=new JmsTargetAdapter();
target.setConnectionFactory(getConnectionFactory());
target.setDestination(destination);
target.setChannel(input);
return input;
}
Any ideas how I can hook this up? If it is possible the setup of a request/response pair would reduce down from the XML shown to just
Code:
Proxy<String, String> proxy=new Proxy<String, String>(STATUS);
Stub<String,String> stub=new Stub<String, String>(STATUS){
public String handle(String payload) {
return "Processed "+payload;
}
};
proxy.start();
stub.start();
String result=proxy.execute("Status: OK");
proxy.stop();
stub.stop();