new PostgresPubSub(config, postgres, logger, serverName [, subscriberName])
Create the service
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
config |
object | Config service | |
postgres |
Postgres | Postgres service | |
logger |
Logger | Logger service | |
serverName |
string | Name of the instance | |
subscriberName |
string |
<optional> |
Name of this pubsub |
Members
-
<static> provides :string
-
Service name is 'postgresPubSub'
Type:
- string
-
<static> requires :Array.<string>
-
Dependencies as constructor arguments
Type:
- Array.<string>
Methods
-
done()
-
Client termination
-
<async> subscribe(channel, handler)
-
Subscribe to a channel
Parameters:
Name Type Description channel
string Channel name handler
Subscriber Handler function Returns:
Resolves on success- Type
- Promise
-
<async> unsubscribe(channel, handler)
-
Unsubscribe from a channel
Parameters:
Name Type Description channel
string Channel name handler
Subscriber Handler function Returns:
Resolves on success- Type
- Promise
-
<async> publish(channel, message)
-
Publish a message after passing it through JSON.stringify()
Parameters:
Name Type Description channel
string Channel name message
* Message Returns:
Resolves on success- Type
- Promise
-
onMessage(channel, message)
-
Message event handler
Parameters:
Name Type Description channel
string Channel name message
string Message -
<async> _getPub()
-
Get PUB client
Returns:
- Type
- Promise
-
<async> _getSub( [subsrcribe])
-
Get SUB client
Parameters:
Name Type Argument Description subsrcribe
string <optional>
Subscribe to this if sub is already created Returns:
- Type
- Promise