Class PostgresChannelMessageTableSubscriber
java.lang.Object
org.springframework.integration.jdbc.channel.PostgresChannelMessageTableSubscriber
- All Implemented Interfaces:
Lifecycle
,Phased
,SmartLifecycle
A subscriber for new messages being received by a Postgres database via a
JdbcChannelMessageStore
. This subscriber implementation is using
Postgres' LISTEN/NOTIFY mechanism to allow for receiving push
notifications for new messages what functions even if a message is written
and read from different JVMs or JdbcChannelMessageStore
s.
Note that this subscriber requires an unshared PgConnection
which
remains open for any lifecycle. It is therefore recommended to execute a single
subscriber for any JVM. For this reason, this subscriber is region-agnostic.
To listen for messages for a given region and group id, use a
PostgresChannelMessageTableSubscriber.Subscription
and register it with this subscriber.
In order to function, the Postgres database that is used must define a trigger
for sending notifications upon newly arrived messages. This trigger is defined
in the schema-postgresql.sql file within this artifact but commented
out.- Since:
- 6.0
- Author:
- Rafael Winterhalter, Artem Bilan, Igor Lovich, Christian Tzolov
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A subscription to aPostgresChannelMessageTableSubscriber
for receiving push notifications for new messages that are added to aJdbcChannelMessageStore
. -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionPostgresChannelMessageTableSubscriber
(PgConnectionSupplier connectionSupplier) Create a new subscriber using theJdbcChannelMessageStore.DEFAULT_TABLE_PREFIX
.PostgresChannelMessageTableSubscriber
(PgConnectionSupplier connectionSupplier, String tablePrefix) Create a new subscriber. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
setExecutor
(ExecutorService executor) Deprecated, for removal: This API element is subject to removal in a future version.void
setTaskExecutor
(AsyncTaskExecutor taskExecutor) Provide a managedAsyncTaskExecutor
for Postgres listener daemon.void
start()
void
stop()
boolean
subscribe
(PostgresChannelMessageTableSubscriber.Subscription subscription) Add a new subscription to this subscriber.boolean
Remove a previous subscription from this subscriber.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, stop
-
Constructor Details
-
PostgresChannelMessageTableSubscriber
Create a new subscriber using theJdbcChannelMessageStore.DEFAULT_TABLE_PREFIX
.- Parameters:
connectionSupplier
- The connection supplier for the targeted Postgres database.
-
PostgresChannelMessageTableSubscriber
public PostgresChannelMessageTableSubscriber(PgConnectionSupplier connectionSupplier, String tablePrefix) Create a new subscriber.- Parameters:
tablePrefix
- The table prefix of theJdbcChannelMessageStore
to subscribe to.connectionSupplier
- The connection supplier for the targeted Postgres database.
-
-
Method Details
-
setExecutor
Deprecated, for removal: This API element is subject to removal in a future version.since 6.2 in favor ofsetTaskExecutor(AsyncTaskExecutor)
Define an executor to use for listening for new messages. Note that the Postgres SQL driver implements listening for notifications as a blocking operation which will permanently block a thread of this executor while running.- Parameters:
executor
- The executor to use ornull
if an executor should be created by this class.
-
setTaskExecutor
Provide a managedAsyncTaskExecutor
for Postgres listener daemon.- Parameters:
taskExecutor
- theAsyncTaskExecutor
to use.- Since:
- 6.2
-
subscribe
Add a new subscription to this subscriber.- Parameters:
subscription
- The subscription to register.- Returns:
true
if the subscription was not already added.
-
unsubscribe
Remove a previous subscription from this subscriber.- Parameters:
subscription
- The subscription to remove.- Returns:
true
if the subscription was previously registered and is now removed.
-
start
public void start() -
stop
public void stop() -
isRunning
public boolean isRunning()
-
setTaskExecutor(AsyncTaskExecutor)