Constructor
new ServiceRegistrationInfo(client, serviceType)
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | The Client instance that will expose this service. |
serviceType |
String | A textual name for the service. For example, "/mycompany/myservice". |
- Source:
Example
// Create service registration object
var info = new dxl.ServiceRegistrationInfo(client, 'myService')
// Add a topic for the service to respond to
info.addTopic(SERVICE_TOPIC,
// Handle the receipt of an incoming service request
function (request) {
// Extract information from request
console.log('Service received request payload: ' + request.payload)
// Create the response message
var response = new dxl.Response(request)
// Populate the response payload
response.payload = 'pong'
// Send the response
client.sendResponse(response)
})
// Register the service with the fabric
client.registerServiceAsync(info,
function (error) {
// If an error did not occur, invoke the service (send a request)
if (!error) {
// Create the request message
var request = new dxl.Request(SERVICE_TOPIC)
// Populate the request payload
request.payload = 'ping'
// Send the request
client.asyncRequest(request,
// Handle the response to the request
function (error, response) {
// Destroy the client - frees up resources so that the
// application stops running
client.destroy()
// Extract information from the response (if an error did not
// occur)
if (!error) {
console.log('Client received response payload: ' +
response.payload)
}
})
}
})
Members
destinationTenantGuids :Array.<String>
The set of tenant identifiers that the service will be available to. Setting this value will limit which tenants can invoke the service.
Type:
- Array.<String>
- Default Value:
- []
- Source:
metadata :Object
An object of name-value pairs that are sent as part of the service registration. Brokers provide a registry service that allows for registered services and their associated meta-information to be inspected. The metadata is typically used to include information such as the versions for products that are exposing DXL services, etc.
Type:
- Object
- Default Value:
- {}
- Source:
serviceId :String
A unique identifier for the service instance (automatically generated when the ServiceRegistrationInfo object is constructed).
Type:
- String
- Source:
serviceType :String
A textual name for the service. For example, "/mycompany/myservice".
Type:
- String
- Source:
topics
Properties:
Type | Description |
---|---|
Array.<String> | An array containing the string name of each topic that the service responds to. |
- Source:
ttl :Number
The interval (in minutes) at which the client will automatically re-register the service with the DXL fabric.
Type:
- Number
- Default Value:
- 60
- Source:
Methods
addTopic(topic, callback)
Registers a topic for the service to respond to along with the request callback that will be invoked.
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | The topic for the service to respond to. |
callback |
function | The request callback that will be invoked when a Request message is received. The Request object is supplied as the only parameter to the request callback function. |
- Source:
addTopics(callbacksByTopic)
Registers a set of topics for the service to respond to along with their associated request callbacks.
Parameters:
Name | Type | Description |
---|---|---|
callbacksByTopic |
Object | Object containing a set of topics for the service to respond to along with their associated request callback instances. Each key in the object should have a string representation of the topic name. Each corresponding value in the object should contain the function to be invoked when a Request message is received. The Request object is supplied as the only parameter to the request callback function. |
- Source:
callbacks(topic) → {Array.<function()>}
Returns an array of functions which should be called upon receipt of a Request with the supplied topic.
Parameters:
Name | Type | Description |
---|---|---|
topic |
String | Topic for which to return associated callback functions. |
- Source:
Returns:
Array of callback functions for the topic.
- Type
- Array.<function()>