This documentation provides a detailed API Websocket guide for the Message Pickup Repository Server. This server manages message queues, live session tracking, and integrates WebSocket-based pub/sub mechanisms.
Retrieves messages from the queue for a specific connection.
- Parameters:
connectionId
: ID of the connection.recipientDid
: Optional DID of the recipient.limit
: Optional limit on the number of messages to retrieve.deleteMessages
: Optional flag to delete messages after retrieval.
- Returns:
QueuedMessage[]
(Array of messages)
Retrieves the number of available messages in the queue for a given connection.
- Parameters:
connectionId
: ID of the connection.recipientDid
: Optional DID of the recipient.
- Returns:
number
(Number of available messages)
Adds a message to the queue for a specific connection.
- Parameters:
connectionId
: ID of the connection.recipientDids
: Array of recipient DIDs.payload
: Encrypted message content.
- Returns:
string
(ID of the added message)
Removes specific messages from the queue for a given connection.
- Parameters:
connectionId
: ID of the connection.messageIds
: Array of message IDs to remove.
- Returns:
void
Removes all messages for a given connection and recipient DID.
- Parameters:
connectionId
: ID of the connection.recipientDid
: DID of the recipient.
- Returns:
void
Retrieves live session data for a given connection.
- Parameters:
connectionId
: ID of the connection.
- Returns:
boolean | null
(True if a live session exists, null otherwise)
Adds a live session for a given connection.
- Parameters:
connectionId
: ID of the connection.sessionId
: ID of the session to add.
- Returns:
boolean
(True if the session was successfully added)
Removes a live session for a given connection.
- Parameters:
connectionId
: ID of the connection.
- Returns:
boolean
(True if the session was successfully removed)
To resolve synchronization across multiple instances the Message Pickup Repository server implements a pub/sub mechanism using Redis cluster to notify clients in real-time about new messages for a specific connectionId
.
- When a new message is added to the queue, the
addMessage()
function publishes an event to the Redis channel associated with theconnectionId
. This notifies any subscribed clients that a new message is available.
-
When the client connect with the server create a
addLiveSession()
, the server subscribes to the Redis channel associated - with the client’sconnectionId
. This allows the server to listen for new messages published for that connection. -
Then a new message is received, the server sends a JSON-RPC response to the client with the new message data.
-
Once the server send JSON-RPC response, the client receives the notification with the message through its subscription to the
messagesReceived
event. The client’s callback function is triggered with the message data.
In the Message Pickup Repository, the sendPushNotification
function is responsible for sending push notifications to clients when they receive new messages. This mechanism ensures that clients are alerted even if they are not LiveSession into the server.
Push notifications are triggered under the following conditions:
- New Message Arrival: Whenever a new message is added to the message queue for a specific
connectionId
, the server checks whether the client is online or not. - Client Offline: If the client is not liveSession, a push notification is sent to notify the client of the new message via FCM Notification Sender API.