| 
									
										
										
										
											2013-09-16 23:11:56 +08:00
										 |  |  | package org.test | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-20 22:21:37 +08:00
										 |  |  | @Grab("org.apache.activemq:activemq-all:5.4.0") | 
					
						
							| 
									
										
										
										
											2013-10-10 22:04:04 +08:00
										 |  |  | @Grab("activemq-pool") | 
					
						
							| 
									
										
										
										
											2013-09-16 23:11:56 +08:00
										 |  |  | import java.util.concurrent.CountDownLatch | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Log | 
					
						
							| 
									
										
										
										
											2014-08-28 20:25:14 +08:00
										 |  |  | @EnableJms | 
					
						
							| 
									
										
										
										
											2013-09-16 23:11:56 +08:00
										 |  |  | class JmsExample implements CommandLineRunner { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private CountDownLatch latch = new CountDownLatch(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	@Autowired | 
					
						
							|  |  |  | 	JmsTemplate jmsTemplate | 
					
						
							| 
									
										
										
										
											2013-09-19 03:17:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void run(String... args) { | 
					
						
							| 
									
										
										
										
											2013-09-16 23:11:56 +08:00
										 |  |  | 		def messageCreator = { session -> | 
					
						
							|  |  |  | 			session.createObjectMessage("Greetings from Spring Boot via ActiveMQ") | 
					
						
							|  |  |  | 		} as MessageCreator | 
					
						
							|  |  |  | 		log.info "Sending JMS message..." | 
					
						
							|  |  |  | 		jmsTemplate.send("spring-boot", messageCreator) | 
					
						
							| 
									
										
										
										
											2014-02-07 07:28:15 +08:00
										 |  |  | 		log.info "Send JMS message, waiting..." | 
					
						
							| 
									
										
										
										
											2013-09-16 23:11:56 +08:00
										 |  |  | 		latch.await() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-28 20:25:14 +08:00
										 |  |  | 	@JmsListener(destination = 'spring-boot') | 
					
						
							| 
									
										
										
										
											2013-11-05 14:02:20 +08:00
										 |  |  | 	def receive(String message) { | 
					
						
							|  |  |  | 		log.info "Received ${message}" | 
					
						
							|  |  |  | 		latch.countDown() | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-28 20:25:14 +08:00
										 |  |  | } |