From 5c762750101f12abd51621355a871e42fd9c7a33 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 May 2014 23:34:16 +0200 Subject: o Getting the web configuration to work. --- .../jenkinsci/plugins/activemq/ActiveMqClient.java | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java') diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java index a40f3e6..ffb4313 100644 --- a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java +++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java @@ -1,6 +1,6 @@ package org.jenkinsci.plugins.activemq; -import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.pool.PooledConnectionFactory; import javax.jms.Connection; import javax.jms.DeliveryMode; @@ -8,6 +8,7 @@ import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; +import javax.jms.TextMessage; import java.io.CharArrayWriter; import java.io.IOException; import java.util.Properties; @@ -17,20 +18,24 @@ import static javax.jms.Session.AUTO_ACKNOWLEDGE; public class ActiveMqClient { - ActiveMQConnectionFactory connectionFactory; + public static final String TOPIC_NAME = "jenkins.build-result"; + + public final String brokerUrl; + private final PooledConnectionFactory connectionFactory; public ActiveMqClient(String brokerUrl) { - this.connectionFactory = new ActiveMQConnectionFactory(brokerUrl); + this.brokerUrl = brokerUrl; + this.connectionFactory = new PooledConnectionFactory(brokerUrl); } - public void sendMessage(String jobName, int buildNumber, String result) { + public synchronized void sendMessage(String jobName, int buildNumber, String result) { try { Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, AUTO_ACKNOWLEDGE); - Destination destination = session.createQueue("jenkins.build-result"); + Destination destination = session.createTopic(TOPIC_NAME); MessageProducer producer = session.createProducer(destination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); @@ -42,7 +47,10 @@ public class ActiveMqClient { CharArrayWriter buf = new CharArrayWriter(); properties.store(buf, null); - producer.send(session.createTextMessage(buf.toString())); + TextMessage message = session.createTextMessage(buf.toString()); + System.out.println("message.getJMSMessageID() = " + message.getJMSMessageID()); + producer.send(message); + System.out.println("message.getJMSMessageID() = " + message.getJMSMessageID()); session.close(); connection.close(); @@ -52,4 +60,8 @@ public class ActiveMqClient { e.printStackTrace(); } } + + public synchronized void close() { + connectionFactory.clear(); + } } -- cgit v1.2.3