package org.jenkinsci.plugins.calamus; import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.MessageProducer; import javax.jms.Session; import static javax.jms.Session.AUTO_ACKNOWLEDGE; public class MqClient { ActiveMQConnectionFactory connectionFactory; public MqClient(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); MapMessage message = session.createMapMessage(); message.setString("jobName", jobName); message.setInt("buildNumber", buildNumber); message.setString("result", result); producer.send(message); session.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } } }