Artemis

Embedded Server

pom.xml

<properties>
  <artemis.version>2.11.0</artemis.version>
</properties>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-artemis</artifactId>
		</dependency>	
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>artemis-jms-server</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.apache.activemq</groupId>
					<artifactId>artemis-jdbc-store</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

application.properties

spring.artemis.mode=EMBEDDED
spring.artemis.embedded.persistent=true
#spring.artemis.host=127.0.0.1
#spring.artemis.port=61617
spring.artemis.embedded.data-directory=mqdir
spring.artemis.embedded.queues=myqueue
spring.jms.template.default-destination=${spring.artemis.embedded.queues}

Sample Code

@Configuration
public class JmsConf {		
	
	@Value("${spring.artemis.port:61616}")
	private int port;
	@Value("${spring.artemis.host:0.0.0.0}")
	private String host;
	
	@Bean
	public MappingJackson2MessageConverter jmsMessageConvert(ObjectMapper objectMapper) {
		
		MappingJackson2MessageConverter convert= new MappingJackson2MessageConverter();
		convert.setTargetType(MessageType.TEXT);
		convert.setTypeIdPropertyName("MyDataObject");
		convert.setTypeIdMappings(Collections.singletonMap("My_DATA_CALSS",MyObj.class));
		convert.setObjectMapper(objectMapper);
		return convert;
	}
	
	@Bean
	public ArtemisConfigurationCustomizer artemisCustom(ApplicationContext ctx) {	
		
		return new ArtemisConfigurationCustomizer() {
			@Override
			public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {				
				Map<String, Object> connectionParams = new HashMap<String, Object>();
				connectionParams.put(TransportConstants.PORT_PROP_NAME,port);
				connectionParams.put(TransportConstants.HOST_PROP_NAME,host);
				TransportConfiguration transportConfiguration =
					    new TransportConfiguration(NettyAcceptorFactory.class.getName(),
					    connectionParams);
				configuration.addAcceptorConfiguration(transportConfiguration);				
				configuration.setMetricsPlugin(new ActiveMQMetrics(ctx));
			}
			
		};
	}
	
	
	private class ActiveMQMetrics implements ActiveMQMetricsPlugin{		
		private ApplicationContext ctx;
		
		public ActiveMQMetrics(ApplicationContext ctx){
			this.ctx=ctx;
		}
		
		@Override
		public ActiveMQMetricsPlugin init(Map<String, String> options) {			
			return this;
		}

		@Override
		public MeterRegistry getRegistry() {
			ObjectProvider<MeterRegistry> op=ctx.getBeanProvider(MeterRegistry.class);					
			return op.getObject();
		}
		
	}
}

JmsTemplate.convertAndSend(obj);

Client

pom.xml

<properties>
  <artemis.version>2.11.0</artemis.version>
</properties>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-artemis</artifactId>
		</dependency>

application.properties

# ARTEMIS embedded MQ
spring.artemis.host=127.0.0.1
spring.artemis.port=61616
spring.jms.template.default-destination=myqueue
spring.jms.cache.consumers=true
spring.jms.cache.producers=false
spring.jms.listener.acknowledge-mode=CLIENT
spring.jms.listener.concurrency=1
spring.jms.listener.max-concurrency=1

Sample Code

@Configuration
public class JmsConf {
	
	@Bean
	public MappingJackson2MessageConverter jmsMessageConvert(ObjectMapper objectMapper) {		
		MappingJackson2MessageConverter convert= new MappingJackson2MessageConverter();
		convert.setTargetType(MessageType.TEXT);
		convert.setTypeIdPropertyName("MyDataObject");
		convert.setTypeIdMappings(Collections.singletonMap("MY_DATA_CALSS",MyObj.class));
		convert.setObjectMapper(objectMapper);
		return convert;
	}
}

@JmsListener(destination ="myqueue")
	public void trigger(@Payload MyObj obj,Session session) throws JMSException {
    session.commit();
    }