new vertx(clientName, settings) → {Object}
Status: Deprecated
The vertx adapter is the default type used when creating a new notifier client. It uses the vert.x bus and underlying SockJS implementation for messaging.
Parameters:
Name | Type | Argument | Default | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
clientName |
String | the name used to reference this particular notifier client | |||||||||||||||||||||||||||||||||||||
settings |
Object |
<optional> |
{} | the settings to be passed to the adapter
Properties
|
- Deprecated:
- since 2.1.0 and will be removed in a future release.
- Source:
Returns:
The created notifier client
- Type
- Object
Example
// Create an empty Notifier
var notifier = AeroGear.Notifier();
// Create a channel object and the channel callback function
var channelObject = {
address: "org.aerogear.messaging.global",
callback: channelCallback
};
function channelCallback( message ) {
console.log( message );
}
// Add a vertx client with all the settings
notifier.add({
name: "client1",
settings: {
autoConnect: true,
connectURL: window.location.protocol + '//' + window.location.host + "/eventbus",
onConnect: function() {
console.log( "connected" );
},
onConnectError: function() {
console.log( "connection error" );
},
onDisconnect: function() {
console.log( "Disconnected" );
},
channels: [ channelObject ]
}
});
Methods
-
connect(options)
-
Connect the client to the messaging service
Parameters:
Name Type Argument Default Description options
Object <optional>
{} Options to pass to the connect method Properties
Name Type Argument Description url
String <optional>
The URL for the messaging service. This url will override and reset any connectURL specified when the client was created. protocols_whitelist
Array <optional>
A list protocols that may be used by SockJS. By default all available protocols will be used, which is equivalent to supplying: "['websocket', 'xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']" onConnect
Function <optional>
callback to be executed when a connection is established onDisconnect
Function <optional>
callback to be executed when a connection is terminated onConnectError
Function <optional>
callback to be executed when connecting to a service is unsuccessful - Source:
Example
// Create an empty Notifier var notifier = AeroGear.Notifier(); // Add a vertx client notifier.add({ name: "client1", settings: { connectURL: window.location.protocol + '//' + window.location.host + "/eventbus", onConnect: function() { console.log( "connected" ); }, onConnectError: function() { console.log( "connection error" ); }, onDisconnect: function() { console.log( "Disconnected" ); } } }); // Connect to the vertx messaging service notifierVertx.clients.client1.connect();
-
disconnect()
-
Disconnect the client from the messaging service
- Source:
Example
// Create an empty Notifier var notifier = AeroGear.Notifier(); // Add a vertx client notifier.add({ name: "client1", settings: { connectURL: window.location.protocol + '//' + window.location.host + "/eventbus", onConnect: function() { console.log( "connected" ); }, onConnectError: function() { console.log( "connection error" ); }, onDisconnect: function() { console.log( "Disconnected" ); } } }); // Connect to the vertx messaging service notifierVertx.clients.client1.connect(); // Disconnect from the vertx messaging service notifierVertx.clients.client1.disconnect();
-
send(channel, message, publish)
-
Send a message to a particular channel
Parameters:
Name Type Argument Default Description channel
String the channel to which to send the message message
String | Object <optional>
"" the message object to send publish
Boolean <optional>
false tell vert.x if this is a publish to all subscribed clients - Source:
Example
// Send an empty message to a channel notifier.clients.client1.send( "test.address" ); // Send a "Hello" message to a channel notifier.clients.client1.send( "test.address", "Hello" ); // Send a "Hello" message as an object notifier.clients.client1.send( "test.address", { "message": "Hello" } ); // Send a "Hello" message as an object to all subscribed clients on that channel notifier.clients.client1.send( "test.address", { "message": "Hello" }, true );
-
subscribe(channels, reset)
-
Subscribe this client to a new channel
Parameters:
Name Type Argument Description channels
Object | Array a channel object or array of channel objects to which this client can subscribe. Each object should have a String address as well as a callback to be executed when a message is received on that channel. reset
Boolean <optional>
if true, remove all channels from the set and replace with the supplied channel(s) - Source:
Example
// Create an empty Notifier var notifier = AeroGear.Notifier(); // Create a channel object and the channel callback function var channelObject = { address: "org.aerogear.messaging.global", callback: channelCallback }; function channelCallback( message ) { console.log( message ); } // Add a vertx client with autoConnect === true and no channels notifier.add({ name: "client1", settings: { autoConnect: true, connectURL: window.location.protocol + '//' + window.location.host + "/eventbus", onConnect: function() { console.log( "connected" ); }, onConnectError: function() { console.log( "connection error" ); }, onDisconnect: function() { console.log( "Disconnected" ); } } }); // Subscribe to a channel notifierVertx.clients.client1.subscribe( channelObject ); // Subscribe to multiple channels at once notifierVertx.clients.client1.subscribe([ { address: "newChannel", callback: function(){...} }, { address: "anotherChannel", callback: function(){ ... } } ]); // Subscribe to a channel, but first unsubscribe from all currently subscribed channels by adding the reset parameter notifierVertx.clients.client1.subscribe({ address: "newChannel", callback: function(){ ... } }, true );
-
unsubscribe(channels)
-
Unsubscribe this client from a channel
Parameters:
Name Type Description channels
Object | Array a channel object or a set of channel objects to which this client nolonger wishes to subscribe. Each object should have a String address and an optional callback which needs to be the same as the callback passed to the subscribe method while subscribing the client to the channel. - Source:
Example
// Unsubscribe from a previously subscribed channel notifierVertx.clients.client1.unsubscribe( { address: "org.aerogear.messaging.global", callback: channelCallback } ); // Unsubscribe from multiple channels notifierVertx.clients.client1.unsubscribe([ { address: "newChannel", callback: newCallbackFunction }, { address: "anotherChannel", callback: "anotherChannelCallbackFunction" } ]);