Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
4581c5a2
Commit
4581c5a2
authored
Jul 07, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rationalize AMQP sample
parent
406d4ea7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
42 deletions
+21
-42
docker-compose.yml
...g-boot-samples/spring-boot-sample-amqp/docker-compose.yml
+5
-0
SampleAmqpSimpleApplication.java
...rc/main/java/sample/amqp/SampleAmqpSimpleApplication.java
+16
-30
Sender.java
...ng-boot-sample-amqp/src/main/java/sample/amqp/Sender.java
+0
-12
No files found.
spring-boot-samples/spring-boot-sample-amqp/docker-compose.yml
0 → 100644
View file @
4581c5a2
rabbitmq
:
image
:
rabbitmq
ports
:
-
"
5672:5672"
-
"
15672:15672"
spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/SampleAmqpSimpleApplication.java
View file @
4581c5a2
...
...
@@ -16,49 +16,35 @@
package
sample
.
amqp
;
import
org.springframework.amqp.core.AmqpTempl
ate
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.
rabbit.listener.SimpleMessageListenerContainer
;
import
org.springframework.amqp.rabbit.
listener.adapter.MessageListenerAdapt
er
;
import
org.springframework.
beans.factory.annotation.Autowired
;
import
java.util.D
ate
;
import
org.springframework.amqp.
core.Queue
;
import
org.springframework.amqp.rabbit.
annotation.RabbitHandl
er
;
import
org.springframework.
amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
;
import
org.springframework.messaging.handler.annotation.Payload
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@SpringBootApplication
@RabbitListener
(
queues
=
"foo"
)
@EnableScheduling
public
class
SampleAmqpSimpleApplication
{
@Autowired
private
AmqpTemplate
amqpTemplate
;
@Autowired
private
ConnectionFactory
connectionFactory
;
@Bean
public
ScheduledAnnotationBeanPostProcessor
scheduledAnnotationBeanPostProcessor
()
{
return
new
ScheduledAnnotationBeanPostProcessor
();
}
@Bean
public
Sender
mySender
()
{
return
new
Sender
();
}
@Bean
public
SimpleMessageListenerContainer
container
()
{
SimpleMessageListenerContainer
container
=
new
SimpleMessageListenerContainer
(
this
.
connectionFactory
);
Object
listener
=
new
Object
()
{
@SuppressWarnings
(
"unused"
)
public
void
handleMessage
(
String
foo
)
{
System
.
out
.
println
(
foo
);
}
};
MessageListenerAdapter
adapter
=
new
MessageListenerAdapter
(
listener
);
container
.
setMessageListener
(
adapter
);
container
.
setQueueNames
(
"foo"
);
return
container
;
public
Queue
fooQueue
()
{
return
new
Queue
(
"foo"
);
}
@RabbitHandler
public
void
process
(
@Payload
String
foo
)
{
System
.
out
.
println
(
new
Date
()
+
": "
+
foo
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
spring-boot-samples/spring-boot-sample-amqp/src/main/java/sample/amqp/Sender.java
View file @
4581c5a2
...
...
@@ -16,10 +16,6 @@
package
sample
.
amqp
;
import
javax.annotation.PostConstruct
;
import
org.springframework.amqp.core.AmqpAdmin
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
...
...
@@ -29,14 +25,6 @@ public class Sender {
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Autowired
private
AmqpAdmin
amqpAdmin
;
@PostConstruct
public
void
setUpQueue
()
{
this
.
amqpAdmin
.
declareQueue
(
new
Queue
(
"foo"
));
}
@Scheduled
(
fixedDelay
=
1000L
)
public
void
send
()
{
this
.
rabbitTemplate
.
convertAndSend
(
"foo"
,
"hello"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment