package org.ihtsdo.telemetry.server;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.ihtsdo.telemetry.core.Constants;

import javax.jms.*;
import java.util.ArrayList;
import java.util.List;

public class TestBroker {

	private final Connection connection;
	private final List<Message> messages;
	private final Session session;

	public TestBroker() throws JMSException {
		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
		connection = connectionFactory.createConnection();
		session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		connection.start();

		messages = new ArrayList<>();

		// Set the test broker url as the default for other components within this JVM.
		System.setProperty(Constants.SYS_PROP_BROKER_URL, "vm://localhost?create=false");
	}

	public void consumeMessages() throws JMSException {
		Queue queue = session.createQueue(Constants.QUEUE_RELEASE_EVENTS);
		final MessageConsumer consumer = session.createConsumer(queue);
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Message receive = consumer.receive();
					if (receive != null) {
						messages.add(receive);
					}
				} catch (JMSException e) {
					e.printStackTrace();
				}
			}
		}).start();
	}

	public void close() throws JMSException {
		connection.close();
	}

	public List<Message> getMessages() {
		return messages;
	}
}

@@ -128,16 +128,73 @@
 nstants;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -394,16 +394,84 @@
 session;
+%0A%09private final Logger logger = LoggerFactory.getLogger(getClass());
 %0A%0A%09publi
@@ -1389,26 +1389,38 @@
 %09%09%09%09
-e.printStackTrace(
+logger.error(%22JMSException%22, e
 );%0A%09

Test embedded JMS broker logging.