public class SpringAMQPPublisher extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware
Axon.EventBus
".
This terminal does not dispatch Events internally, as it relies on each event processor to listen to it's own AMQP Queue.
Constructor and Description |
---|
SpringAMQPPublisher(SubscribableMessageSource<EventMessage<?>> messageSource)
Initialize this instance to publish message as they are published on the given
messageSource . |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doSendMessage(com.rabbitmq.client.Channel channel,
AMQPMessage amqpMessage)
Does the actual publishing of the given
body on the given channel . |
protected void |
send(List<? extends EventMessage<?>> events)
Sends the given
events to the configured AMQP Exchange. |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory connectionFactory)
Sets the ConnectionFactory providing the Connections and Channels to send messages on.
|
void |
setDurable(boolean durable)
Whether or not messages should be marked as "durable" when sending them out.
|
void |
setExchange(org.springframework.amqp.core.Exchange exchange)
Sets the name of the exchange to dispatch published messages to.
|
void |
setExchangeName(String exchangeName)
Sets the name of the exchange to dispatch published messages to.
|
void |
setMessageConverter(AMQPMessageConverter messageConverter)
Sets the Message Converter that creates AMQP Messages from Event Messages and vice versa.
|
void |
setPublisherAckTimeout(long publisherAckTimeout)
Sets the maximum amount of time (in milliseconds) the publisher may wait for the acknowledgement of published
messages.
|
void |
setRoutingKeyResolver(RoutingKeyResolver routingKeyResolver)
Sets the RoutingKeyResolver that provides the Routing Key for each message to dispatch.
|
void |
setSerializer(Serializer serializer)
Sets the serializer to serialize messages with when sending them to the Exchange.
|
void |
setTransactional(boolean transactional)
Whether this Terminal should dispatch its Events in a transaction or not.
|
void |
setWaitForPublisherAck(boolean waitForPublisherAck)
Enables or diables the RabbitMQ specific publisher acknowledgements (confirms).
|
void |
shutDown()
Shuts down this component and unsubscribes it from its messageSource.
|
void |
start()
Subscribes this publisher to the messageSource provided during initialization.
|
public SpringAMQPPublisher(SubscribableMessageSource<EventMessage<?>> messageSource)
messageSource
.messageSource
- The component providing messages to be publishespublic void start()
public void shutDown()
protected void send(List<? extends EventMessage<?>> events)
events
to the configured AMQP Exchange. It takes the current Unit of Work into account
when available. Otherwise, it simply publishes directly.events
- the events to publish on the AMQP Message Brokerprotected void doSendMessage(com.rabbitmq.client.Channel channel, AMQPMessage amqpMessage) throws IOException
body
on the given channel
. This method can be
overridden to change the properties used to send a message.channel
- The channel to dispatch the message onamqpMessage
- The AMQPMessage describing the characteristics of the message to publishIOException
- when an error occurs while writing the messagepublic void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void setTransactional(boolean transactional)
false
.
If a delegate Terminal is configured, the transaction will be committed after the delegate has dispatched the events.
Transactional behavior cannot be enabled if setWaitForPublisherAck(boolean)
has been set to
true
.
transactional
- whether dispatching should be transactional or notpublic void setWaitForPublisherAck(boolean waitForPublisherAck)
Server ACKS cannot be enabled when transactions are enabled.
See RabbitMQ Documentation for more information about publisher acknowledgements.
waitForPublisherAck
- whether or not to enab;e server acknowledgements (confirms)public void setPublisherAckTimeout(long publisherAckTimeout)
This setting is only used when setWaitForPublisherAck(boolean)
is set to true
.
publisherAckTimeout
- The number of milliseconds to wait for confirms, or 0 to wait indefinitely.public void setConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory connectionFactory)
send(List)
Defaults to an autowired Connection Factory.
connectionFactory
- The connection factory to setpublic void setMessageConverter(AMQPMessageConverter messageConverter)
Defaults to a DefaultAMQPMessageConverter.
messageConverter
- The message converter to convert AMQP Messages to Event Messages and vice versa.public void setDurable(boolean durable)
By default, messages are durable.
Note that this setting is ignored if a MessageConverter
is provided.
In that case, the message converter must add the properties to reflect the required durability setting.
durable
- whether or not messages should be durablepublic void setSerializer(Serializer serializer)
Defaults to an autowired serializer, which requires exactly 1 eligible serializer to be present in the application context.
This setting is ignored if a MessageConverter
is configured.
serializer
- the serializer to serialize message withpublic void setRoutingKeyResolver(RoutingKeyResolver routingKeyResolver)
PackageRoutingKeyResolver
, which uses the package name of the message's
payload as a Routing Key.
This setting is ignored if a MessageConverter
is configured.
routingKeyResolver
- the RoutingKeyResolver to usepublic void setExchangeName(String exchangeName)
Axon.EventBus
".exchangeName
- the name of the exchange to dispatch messages topublic void setExchange(org.springframework.amqp.core.Exchange exchange)
Axon.EventBus
".exchange
- the exchange to dispatch messages topublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
Copyright © 2010–2017. All rights reserved.