Skip to content

Instantly share code, notes, and snippets.

@madan712
Last active June 1, 2020 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madan712/9e5870b11f6e3e778338f9ad843959e9 to your computer and use it in GitHub Desktop.
Save madan712/9e5870b11f6e3e778338f9ad843959e9 to your computer and use it in GitHub Desktop.
TestJmsServerApplication.java - Spring boot ActiveMQ example
package com.javaxp.testjmsserver;
import java.time.LocalDateTime;
import javax.jms.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.core.JmsMessagingTemplate;
@SpringBootApplication
@EnableJms
public class TestJmsServerApplication implements CommandLineRunner {
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;
@Autowired
private Queue queue;
public static void main(String[] args) {
SpringApplication.run(TestJmsServerApplication.class, args);
}
@Bean
public Queue queue() {
return new ActiveMQQueue("myQueue");
}
@Override
public void run(String... args) throws Exception {
while(true) {
Thread.sleep(2000);
LocalDateTime time = LocalDateTime.now();
System.out.println("Sending message from server at " + time);
this.jmsMessagingTemplate.convertAndSend(this.queue,
"Hello JMS at " + time);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment