Package io.vertx.pgclient.pubsub
Interface PgSubscriber
-
public interface PgSubscriber
A class for managing subscriptions usingLISTEN/UNLISTEN
to Postgres channels. The subscriber manages a single connection to Postgres.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description PgConnection
actualConnection()
PgChannel
channel(String name)
Return a channel for the givenname
.Future<Void>
close()
Close the subscriber, the retry policy will not be invoked.boolean
closed()
PgSubscriber
closeHandler(Handler<Void> handler)
Set an handler called when the subscriber is closed.Future<Void>
connect()
Connect the subscriber to Postgres.PgSubscriber
reconnectPolicy(java.util.function.Function<Integer,Long> policy)
Set the reconnect policy that is executed when the subscriber is disconnected.static PgSubscriber
subscriber(Vertx vertx, PgConnectOptions options)
Create a subscriber.
-
-
-
Method Detail
-
subscriber
static PgSubscriber subscriber(Vertx vertx, PgConnectOptions options)
Create a subscriber.- Parameters:
vertx
- the vertx instanceoptions
- the connect options- Returns:
- the subscriber
-
channel
PgChannel channel(String name)
Return a channel for the givenname
.- Parameters:
name
- the channel name This will be the name of the channel exactly as held by Postgres for sending notifications. Internally this name will be truncated to the Postgres identifier maxiumum length of(NAMEDATALEN = 64) - 1 == 63
characters, and prepared as a quoted identifier without unicode escape sequence support for use inLISTEN/UNLISTEN
commands. Examples of channel names and correspondingNOTIFY
commands:- when
name == "the_channel"
:NOTIFY the_channel, 'msg'
,NOTIFY The_Channel, 'msg'
, orNOTIFY "the_channel", 'msg'
succeed in delivering a message to the created channel - when
name == "The_Channel"
:NOTIFY "The_Channel", 'msg'
, succeeds in delivering a message to the created channel
- when
- Returns:
- the channel
-
connect
Future<Void> connect()
Connect the subscriber to Postgres.- Returns:
- a future notified of the connection success or failure
-
reconnectPolicy
PgSubscriber reconnectPolicy(java.util.function.Function<Integer,Long> policy)
Set the reconnect policy that is executed when the subscriber is disconnected. When the subscriber is disconnected, thepolicy
function is called with the actual number of retries and returns anamountOfTime
value:- when
amountOfTime < 0
: the subscriber is closed and there is no retry - when
amountOfTime == 0
: the subscriber retries to connect immediately - when
amountOfTime > 0
: the subscriber retries afteramountOfTime
milliseconds
- Parameters:
policy
- the policy to set- Returns:
- a reference to this, so the API can be used fluently
- when
-
closeHandler
PgSubscriber closeHandler(Handler<Void> handler)
Set an handler called when the subscriber is closed.- Parameters:
handler
- the handler- Returns:
- a reference to this, so the API can be used fluently
-
actualConnection
PgConnection actualConnection()
- Returns:
- the actual connection to Postgres, it might be
null
-
closed
boolean closed()
- Returns:
- whether the subscriber is closed
-
-