summaryrefslogtreecommitdiff
path: root/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java')
-rw-r--r--src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java
new file mode 100644
index 0000000..a40f3e6
--- /dev/null
+++ b/src/main/java/org/jenkinsci/plugins/activemq/ActiveMqClient.java
@@ -0,0 +1,55 @@
+package org.jenkinsci.plugins.activemq;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.util.Properties;
+
+import static java.lang.String.valueOf;
+import static javax.jms.Session.AUTO_ACKNOWLEDGE;
+
+public class ActiveMqClient {
+
+ ActiveMQConnectionFactory connectionFactory;
+
+ public ActiveMqClient(String brokerUrl) {
+ this.connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
+ }
+
+ public 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");
+
+ MessageProducer producer = session.createProducer(destination);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ Properties properties = new Properties();
+ properties.setProperty("jobName", jobName);
+ properties.setProperty("buildNumber", valueOf(buildNumber));
+ properties.setProperty("result", result);
+
+ CharArrayWriter buf = new CharArrayWriter();
+ properties.store(buf, null);
+ producer.send(session.createTextMessage(buf.toString()));
+
+ session.close();
+ connection.close();
+ } catch (JMSException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}