Package org.mockserver.async.subscribe
Class AmqpMessageSubscriber
java.lang.Object
org.mockserver.async.subscribe.AmqpMessageSubscriber
- All Implemented Interfaces:
MessageSubscriber
A
MessageSubscriber that consumes from an AMQP 0.9.1 broker (RabbitMQ)
using the official com.rabbitmq:amqp-client library, the consumer-side
counterpart of AmqpMessagePublisher.
Like the publisher, the AMQP source of a channel is derived from the channel's
AmqpBinding (channels.<name>.bindings.amqp) — the AsyncAPI channel
name does not map directly to a queue the way a Kafka/MQTT topic does:
is: queue(or no binding) — consume directly from the queue named byqueue.name(or the channel name). The queue is declared (durable perqueue.durable) so recording works against a fresh broker, matching the publisher's queue declaration.is: routingKey— declare the binding'sexchange.name(idempotently, with the binding's type/durability), declare a private server-named exclusive auto-delete queue, and bind it to the exchange on the routing key (the binding's explicitroutingKey, else the channel name). Messages published to that exchange/routing-key are then recorded.
Recorded messages carry the AMQP message-property headers (if any) as the
RecordedMessage headers; the key is always null (AMQP has no per-message
key concept the way Kafka does). Recorded messages are stored in a bounded
BoundedMessageStore per channel to prevent unbounded memory growth.
-
Constructor Summary
ConstructorsConstructorDescriptionAmqpMessageSubscriber(String amqpUri, AsyncApiSpec spec, int maxRecordedMessages) Connect to an AMQP broker from a connection URI and resolve per-channel consume sources from the given spec. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clear all recorded messages and stop all subscriptions.Return all messages recorded across all channels.getRecordedMessages(String channelName) Return all messages recorded on the given channel since subscription started (or since the last reset).voidStart subscribing to the given channel.voidunsubscribe(String channelName) Stop subscribing to the given channel.
-
Constructor Details
-
AmqpMessageSubscriber
Connect to an AMQP broker from a connection URI and resolve per-channel consume sources from the given spec.- Parameters:
amqpUri- the AMQP connection URI (e.g.amqp://user:pass@host:5672/vhost)spec- the loaded AsyncAPI spec (used to map channel names to AMQP bindings); may be nullmaxRecordedMessages- maximum recorded messages retained per channel
-
-
Method Details
-
subscribe
Description copied from interface:MessageSubscriberStart subscribing to the given channel. Messages will be recorded internally and are retrievable viaMessageSubscriber.getRecordedMessages(String).- Specified by:
subscribein interfaceMessageSubscriber- Parameters:
channelName- the channel/topic to subscribe to
-
unsubscribe
Description copied from interface:MessageSubscriberStop subscribing to the given channel.- Specified by:
unsubscribein interfaceMessageSubscriber
-
getRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded on the given channel since subscription started (or since the last reset).- Specified by:
getRecordedMessagesin interfaceMessageSubscriber
-
getAllRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded across all channels.- Specified by:
getAllRecordedMessagesin interfaceMessageSubscriber
-
close
public void close()Description copied from interface:MessageSubscriberClear all recorded messages and stop all subscriptions.- Specified by:
closein interfaceMessageSubscriber
-