Add amqp10 module: AMQP 1.0 in Spring Boot 4.2 with RabbitMQ 4
Generic spring-boot-starter-amqp (AmqpClient, @AmqpListener) and RabbitMQ's own AMQP 1.0 client against a real RabbitMQ 4.4.1 broker via Testcontainers. Transcripts in amqp10/output/ are written by the tests; no docs/ folder. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b44H98Yd627wauSpzA
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
78fc41e586
commit
e54cf840fd
@@ -0,0 +1,12 @@
|
||||
$ docker image: rabbitmq:4-management
|
||||
rabbitmq_version = 4.4.1
|
||||
erlang_version = 29.1.3
|
||||
$ rabbitmq-plugins list -E -m
|
||||
Listing plugins with pattern ".*" ...
|
||||
rabbitmq_management
|
||||
rabbitmq_prometheus
|
||||
listeners:
|
||||
amqp on port 5672
|
||||
clustering on port 25672
|
||||
http on port 15672
|
||||
http/prometheus on port 15692
|
||||
@@ -0,0 +1,9 @@
|
||||
$ AmqpClient.to("/queues/orders.generic").body(order).send()
|
||||
send o-1 -> accepted=true
|
||||
send o-2 -> accepted=true
|
||||
send o-3 -> accepted=true
|
||||
@AmqpListener received 3: [o-1, o-2, o-3]
|
||||
queue orders.generic: type=quorum consumers=1 messages=0
|
||||
$ rabbitmqctl list_connections protocol user
|
||||
protocol user
|
||||
{1, 0} guest
|
||||
@@ -0,0 +1,11 @@
|
||||
what the broker holds (management API, 0-9-1 view of an AMQP 1.0 message):
|
||||
payload = {"id":"p-1","item":"mouse","qty":3}
|
||||
content_type = application/json
|
||||
headers = {"__TypeId__":"com.ankurm.amqp10.OrderMessage"}
|
||||
depth before pulling = 2
|
||||
$ untyped: Object o = from("/queues/orders.pull").receiveAndConvert().get()
|
||||
-> java.lang.IllegalArgumentException: The class 'com.ankurm.amqp10.OrderMessage' is not in the trusted packages: [java.util, jav...
|
||||
depth after the failed conversion = 1
|
||||
$ typed: CompletableFuture<OrderMessage> f = from(...).receiveAndConvert()
|
||||
-> OrderMessage[id=p-2, item=dock, qty=1]
|
||||
depth after the typed pull = 0
|
||||
@@ -0,0 +1,10 @@
|
||||
to("/queues/orders.generic")
|
||||
returned true after 13 ms
|
||||
to("/queues/does.not.exist")
|
||||
threw AmqpClientNackReceivedException: The message was not accepted, but RELEASED after 5 ms
|
||||
to("orders.generic")
|
||||
threw AmqpClientNackReceivedException: The message was not accepted, but REJECTED after 5 ms
|
||||
to("/queue/orders.generic")
|
||||
threw AmqpClientNackReceivedException: The message was not accepted, but REJECTED after 2 ms
|
||||
to("/exchanges/amq.direct/nobody-listens")
|
||||
threw AmqpClientNackReceivedException: The message was not accepted, but RELEASED after 2 ms
|
||||
@@ -0,0 +1,12 @@
|
||||
no spring.amqp.username / password set:
|
||||
context started = true
|
||||
send -> true (context up in 953 ms); broker sees: {1, 0} guest
|
||||
username=guest password=wrong:
|
||||
context started = false
|
||||
javax.security.sasl.AuthenticationException: SASL exchange failed to authenticate client (3271 ms)
|
||||
username=guest password=guest:
|
||||
context started = true
|
||||
send -> true (context up in 988 ms); broker sees: {1, 0} guest
|
||||
port=1 (nothing listens):
|
||||
context started = false
|
||||
java.net.ConnectException: finishConnect(..) failed with error(-111): Connection refused (202 ms)
|
||||
@@ -0,0 +1,14 @@
|
||||
beans from spring-boot-starter-amqp-rabbitmq (no @Bean written for them):
|
||||
RabbitAmqpTemplate [rabbitAmqpTemplate]
|
||||
RabbitAmqpAdmin [rabbitAmqpAdmin]
|
||||
RabbitAmqpListenerContainerFactory [rabbitListenerContainerFactory]
|
||||
AmqpConnectionFactory [amqpRabbitConnectionFactory]
|
||||
declared by RabbitAmqpAdmin:
|
||||
queue orders.rabbit type=quorum durable=true
|
||||
exchange orders.topic type=topic
|
||||
binding orders.topic -> orders.rabbit key=orders.created
|
||||
$ template.convertAndSend("orders.topic", "orders.created", order).get() -> true
|
||||
@RabbitListener(queues = "orders.rabbit") received OrderMessage[id=r-1, item=router, qty=2]
|
||||
unroutable key : threw AmqpNackReceivedException: The message was rejected after 4 ms
|
||||
missing exchange: threw AmqpMessageRejectedException: no exchange 'no.such.exchange' in vhost '/' after 2 ms
|
||||
$ rabbitmqctl list_connections protocol -> an AMQP 1.0 connection is open: true
|
||||
@@ -0,0 +1,16 @@
|
||||
0-9-1 producer (RabbitTemplate) -> AMQP 1.0 consumer (AmqpClient.receive):
|
||||
body = {"id":"i-1","item":"classic","qty":1}
|
||||
messageId = m-classic
|
||||
correlationId = c-classic
|
||||
contentType = application/json
|
||||
deliveryMode = null
|
||||
headers = {attempt=3, tenant=acme}
|
||||
AMQP 1.0 producer (AmqpClient.to) -> 0-9-1 consumer (RabbitTemplate.receive):
|
||||
body = {"id":"i-2","item":"amqp10","qty":2}
|
||||
messageId = m-amqp10
|
||||
correlationId = c-amqp10
|
||||
contentType = application/json
|
||||
deliveryMode = PERSISTENT
|
||||
headers = {__TypeId__=com.ankurm.amqp10.OrderMessage, attempt=3, tenant=acme}
|
||||
$ rabbitmqctl list_connections protocol, while both clients are connected:
|
||||
AMQP 0-9-1 connection open = true, AMQP 1.0 connection open = true
|
||||
@@ -0,0 +1,7 @@
|
||||
container errorHandler (Boot's default factory) = null
|
||||
one bad message sent to each queue, listener always throws:
|
||||
listener attempts consumers messages left in queue
|
||||
plain exception, autoAccept default 1 0 1 (the bad message was lost; the follow-up is waiting)
|
||||
AmqpRejectAndDontRequeueException 1 0 0
|
||||
plain exception, autoAccept=false 1 0 1 (released back, but nobody is left to take it)
|
||||
follow-up message good-1 delivered to the plain listener? attempts still = 1
|
||||
@@ -0,0 +1,6 @@
|
||||
container errorHandler = set (lambda)
|
||||
with a container ErrorHandler (HandledFactoryConfig), one bad message per queue:
|
||||
plain exception, autoAccept default : 1 attempt(s); follow-up good-1 reached the listener = true
|
||||
AmqpRejectAndDontRequeueException : 1 attempt(s)
|
||||
plain exception, autoAccept=false : 1877 attempts in 3 seconds (figure varies per run, still counting)
|
||||
queue orders.poison.manual depth now : 2
|
||||
@@ -0,0 +1,57 @@
|
||||
Spring Boot 4.2.0
|
||||
|
||||
== spring-boot-starter-amqp: description and dependencies
|
||||
<description>Starter for generic AMQP 1.0 support</description>
|
||||
<artifactId>spring-boot-amqp</artifactId>
|
||||
|
||||
== spring-boot-starter-amqp-rabbitmq: description and dependencies
|
||||
<description>Starter for using Spring AMQP with Rabbit MQ over AMQP 1.0 protocol</description>
|
||||
<artifactId>spring-boot-amqp-rabbitmq</artifactId>
|
||||
|
||||
== spring-boot-starter-rabbitmq: description and dependencies
|
||||
<description>Starter for using RabbitMQ messaging and streaming broker</description>
|
||||
<artifactId>spring-boot-rabbitmq</artifactId>
|
||||
|
||||
== spring-boot-amqp auto-configuration classes
|
||||
org.springframework.boot.amqp.autoconfigure.AmqpAutoConfiguration
|
||||
|
||||
== spring-boot-amqp properties (spring.amqp.*)
|
||||
spring.amqp.client.completion-timeout default=60s
|
||||
spring.amqp.client.default-to-address default=None
|
||||
spring.amqp.host default=localhost
|
||||
spring.amqp.listener.auto-startup default=True
|
||||
spring.amqp.listener.concurrency default=1
|
||||
spring.amqp.listener.default-requeue-rejected default=True
|
||||
spring.amqp.listener.graceful-shutdown-period default=30s
|
||||
spring.amqp.listener.initial-credits default=100
|
||||
spring.amqp.listener.receive-timeout default=1s
|
||||
spring.amqp.password default=None
|
||||
spring.amqp.port default=5672
|
||||
spring.amqp.username default=None
|
||||
|
||||
== spring-boot-amqp-rabbitmq auto-configuration classes
|
||||
org.springframework.boot.amqp.rabbitmq.autoconfigure.AmqpRabbitAutoConfiguration
|
||||
org.springframework.boot.amqp.rabbitmq.autoconfigure.health.AmqpRabbitHealthContributorAutoConfiguration
|
||||
|
||||
== spring-boot-amqp-rabbitmq properties (spring.amqp.rabbitmq.*)
|
||||
spring.amqp.rabbitmq.address default=None
|
||||
spring.amqp.rabbitmq.host default=localhost
|
||||
spring.amqp.rabbitmq.password default=None
|
||||
spring.amqp.rabbitmq.port default=None
|
||||
spring.amqp.rabbitmq.username default=None
|
||||
|
||||
== spring-boot-rabbitmq auto-configuration classes
|
||||
org.springframework.boot.rabbitmq.autoconfigure.RabbitAutoConfiguration
|
||||
org.springframework.boot.rabbitmq.autoconfigure.health.RabbitHealthContributorAutoConfiguration
|
||||
org.springframework.boot.rabbitmq.autoconfigure.metrics.RabbitMetricsAutoConfiguration
|
||||
== spring-boot-rabbitmq properties (selected spring.rabbitmq.*)
|
||||
spring.rabbitmq.host default=localhost
|
||||
spring.rabbitmq.password default=guest
|
||||
spring.rabbitmq.port default=None
|
||||
spring.rabbitmq.username default=guest
|
||||
spring.rabbitmq.virtual-host default=None
|
||||
|
||||
== which Boot module wires RabbitMQ's AMQP 1.0 client (RabbitAmqpTemplate)?
|
||||
spring-boot-amqp: auto-configuration classes mentioning RabbitAmqpTemplate: no
|
||||
spring-boot-amqp-rabbitmq: auto-configuration classes mentioning RabbitAmqpTemplate: yes
|
||||
spring-boot-rabbitmq: auto-configuration classes mentioning RabbitAmqpTemplate: no
|
||||
Reference in New Issue
Block a user