java messaging service spring boot

Solutions on MaxInterview for java messaging service spring boot by the best coders in the world

showing results for - "java messaging service spring boot"
Jak
02 Sep 2017
1package hello;
2
3import javax.jms.ConnectionFactory;
4
5import org.springframework.boot.SpringApplication;
6import org.springframework.boot.autoconfigure.SpringBootApplication;
7import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
8import org.springframework.context.ConfigurableApplicationContext;
9import org.springframework.context.annotation.Bean;
10import org.springframework.jms.annotation.EnableJms;
11import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
12import org.springframework.jms.config.JmsListenerContainerFactory;
13import org.springframework.jms.core.JmsTemplate;
14import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
15import org.springframework.jms.support.converter.MessageConverter;
16import org.springframework.jms.support.converter.MessageType;
17
18@SpringBootApplication
19@EnableJms
20public class Application {
21
22  @Bean
23  public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
24                          DefaultJmsListenerContainerFactoryConfigurer configurer) {
25    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
26    // This provides all boot's default to this factory, including the message converter
27    configurer.configure(factory, connectionFactory);
28    // You could still override some of Boot's default if necessary.
29    return factory;
30  }
31
32  @Bean // Serialize message content to json using TextMessage
33  public MessageConverter jacksonJmsMessageConverter() {
34    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
35    converter.setTargetType(MessageType.TEXT);
36    converter.setTypeIdPropertyName("_type");
37    return converter;
38  }
39
40  public static void main(String[] args) {
41    // Launch the application
42    ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
43
44    JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
45
46    // Send a message with a POJO - the template reuse the message converter
47    System.out.println("Sending an email message.");
48    jmsTemplate.convertAndSend("mailbox", new Email("info@example.com", "Hello"));
49  }
50
51}Copy