Send/Receive Messages
Use this content when building an application that will connect to the app2app service in order to send and receive messages.
Connecting your application to the service
Navigate to the App2app service dashboard and create a destination if you don't have one. A panel titled "My Destinations" will appear showing the service API endpoint.
Connect your application to this endpoint using Socket IO (https://socket.io). Include the following property in the “extraHeaders” connection options:
Authorization: <based64 encoding of app-cred-user:app-cred-password>
Sending messages
Emit a “produce” Socket IO event passing a message object parameter with the following properties:
Name | Type | Required | Description |
---|---|---|---|
from | string | Yes | Sender destination URI |
to | string | Yes | Recipient destination URI |
content | string or Buffer | Yes | Message content |
signature | string or Buffer | Only when sending messages from an externally managed destination | RSA-SHA256 signature of the message content |
Optional parameters:
- message key: string used for coordination and delivery confirmation
- callback: function that takes two parameters:
- error: diagnostic information in string format or null if no errors were detected
- result: constant “Message sent.” If the message was generated
In order to receive delivery reports, add a Socket IO listener to the event “delivery-report”. Listeners will be invoked with these parameters:
- result: string containing a serialized JSON object with the following properties:
Name | Type | Description |
---|---|---|
key | string | Optional message key parameter |
timestamp | number | Message transmission time stamp |
Receiving messages
Emit a “subscribe” Socket IO event passing an array of destination URIs. Optional parameters:
- callback: function that takes two parameters:
- error: diagnostic information in string format or null if no errors were detected
- result: constant “Subscribed.” If the subscription was successful
Add a Socket IO listener to the event “message”. Listeners will be invoked with these parameters:
Parameter order | Type | Description |
---|---|---|
1 (message) | String | When recipient is a Kaleido managed destination: Serialized JSON object containing the message When recipient is an externally managed destination: PKCS7 PEM containing the encrypted message |
2 (key) | String | Optional message key set by the sender |
3 (timestamp) | number | message transmission time stamp (number) |