Hi:
I am writing some code using the org.apache.activemq.network.jms package. In
particular, I am writing my own implementation of JmsConnector. I noticed
that the package currently does not support replyTo Destinations for
outbound message (see JmsTopicConnector.createReplyToBridge), but I think
this feature is necessary to have.
In order to handle replyTo Destinations for outbound message, a couple of
changes are need:
1. add a method to interface JmsMesageConvertor
public Message convert(Message message, Destination replyTo) throws
JMSException;
2. the DestinationBridge onMessage method also need to be changed slightly
original implementation:
public void onMessage(Message message){
if(started.get()&&message!=null){
try{
if(doHandleReplyTo){
Destination
replyTo=message.getJMSReplyTo();
if(replyTo!=null){
replyTo=processReplyToDestination(replyTo);
message.setJMSReplyTo(replyTo);
}
}else {
message.setJMSReplyTo(null);
}
Message converted=
jmsMessageConvertor.convert(message);
sendMessage(converted);
message.acknowledge();
}catch(JMSException e){
log.error("failed to forward
message: "+message,e);
try{
stop();
}catch(Exception e1){
log.warn("Failed
to stop cleanly",e1);
}
}
}
}
changed implementation
public void onMessage(Message message){
if(started.get()&&message!=null){
try{
Message converted;
if(doHandleReplyTo){
Destination
replyTo = message.getJMSReplyTo();
if(replyTo
!= null){
converted = jmsMessageConvertor.convert(message,
processReplyToDestination(replyTo));
} else {
converted = jmsMessageConvertor.convert(message);
}
} else {
message.setJMSReplyTo(null);
converted =
jmsMessageConvertor.convert(message);
}
sendMessage(converted);
message.acknowledge();
}catch(JMSException e){
log.error("failed to forward
message: "+message,e);
try{
stop();
}catch(Exception e1){
log.warn("Failed
to stop cleanly",e1);
}
}
}
}
These changes are needed because setting JMSReplyTo header to
TemporaryDestination of another JMS implementation may throw exception.
Also, I think it is better for the JmsMesageConvertor to use the Connections
of the JmsConnector it associates with, rather than creating its own
Connections, so I am wondering if it is possible to add the following two
methods to the JmsMesageConvertor interface:
public void setTopicConnection(TopicConnection connection);
public void setQueueConnection(QueueConnection connection);
Thank you
Fan Li