diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java index 7e8ab67c64..ab47580674 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/QueueBridge.java @@ -71,7 +71,7 @@ class QueueBridge extends DestinationBridge{ return consumer; } - protected MessageProducer createProducer() throws JMSException{ + protected synchronized MessageProducer createProducer() throws JMSException{ producerSession=producerConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); producer = producerSession.createSender(null); return producer; @@ -80,7 +80,10 @@ class QueueBridge extends DestinationBridge{ - protected void sendMessage(Message message) throws JMSException{ + protected synchronized void sendMessage(Message message) throws JMSException{ + if (producer == null) { + createProducer(); + } producer.send(producerQueue,message); } diff --git a/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java b/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java index 9f45f3ee5e..2325dc8f3b 100755 --- a/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java +++ b/activemq-core/src/main/java/org/apache/activemq/network/jms/TopicBridge.java @@ -79,13 +79,16 @@ class TopicBridge extends DestinationBridge{ - protected MessageProducer createProducer() throws JMSException{ + protected synchronized MessageProducer createProducer() throws JMSException{ producerSession=producerConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); producer = producerSession.createPublisher(null); return producer; } - protected void sendMessage(Message message) throws JMSException{ + protected synchronized void sendMessage(Message message) throws JMSException{ + if (producer == null) { + createProducer(); + } producer.publish(producerTopic,message); }