RabbitMQ
The RabbitMQ module allows you to broadcast information on a RabbitMQ bus. For example, you can use it to push alert or Situation data to a data warehouse via RabbitMQ.
You cannot connect the RabbitMQ Moobot module to the RabbitMQ instance used by Moogsoft AIOps.
Configure the module
To use the RabbitMQ Moobot module:
-
Define a new global object
rabbit
at the top of a Moobot JavaScript file to load the module. -
Use the
connect
method to create a new connection to one or more RabbitMQ brokers. -
Use the
send
method to send the required information. -
Use the
close
method to close the connection.
Refer to the Examples for more details.
Reference Guide
You can use the following methods in the RabbitMQ Moobot module.
connect
Establishes a connection to one or more RabbitMQ brokers with defined connection properties.
You cannot connect the RabbitMQ Moobot module to the RabbitMQ instance used by Moogsoft AIOps.
Request Argument
Name |
Type |
Description |
---|---|---|
<properties> |
Object |
A JavaScript object containing connection properties. See below. |
RabbitMQ Connection Properties
The RabbitMQ module connect
method defines connection
properties as a Javascript object, which may include the following keys:
Key |
Description |
---|---|
|
Top-level container for one or more target RabbitMQ brokers. For each broker, define:
|
|
Username to connect to RabbitMQ. |
|
Username to connect to RabbitMQ. |
|
Length of time to wait before halting a connection or read attempt, in milliseconds. Defaults to 10,000. |
|
Name of the RabbitMQ virtual host. Optional. |
|
Top-level container for the SSL configuration. Optional. |
|
The SSL protocol to use. If not specified, TLSv1.2 is used by default. |
|
Name of the SSL root CA file. |
|
Name of the SSL client certificate. |
|
Name of the SSL client key file. Must be in PKCS#8 format. Refer to Message System SSL for more information. |
Return Parameter
Type |
Description |
---|---|
Object |
A Java object containing connection details, depending on the requested connection properties. Returns |
Example
{ brokers: [ { host: "rabbithost", port: 5672 }], user: "rabbitmq_admin", password: "78smr9!b", timeout: 10000, vhost: "rabbitvhost", ssl: { ssl_protocol: "TLSv1.2", server_cert_file: "server.pem", client_cert_file: "client.pem", client_key_file: "client.key" } }
send
Sends a message to the RabbitMQ broker. Refer to the basic class in the RabbitMQ AMQP 0-9-1 Reference for a list of keys that you can specify in the message properties.
Name |
Type |
Description |
---|---|---|
|
String |
The RabbitMQ exchange. |
|
String |
The RabbitMQ routing key. |
|
String or Object |
Message properties in one of the following formats:
|
|
String |
The message to send. |
Return Parameter
None.
Example
connection.send("direct_logs", "severity", { content-type : "text/xml", reply-to : "greetings.hi", headers : {"server" "app5.myapp.megacorp.com" "cached" false} }, "<Priority>1</Priority>" ) connection.send("topic_logs", "topic", {contentType: "text/xml"}, "<Priority>1</Priority>");
close
Closes the connection to the RabbitMQ broker.
Request Arguments
None.
Return Parameter
Type |
Description |
---|---|
Boolean |
Indicates whether the close operation was successful. |
Examples
The following examples demonstrate the use of the RabbitMQ Moobot module:
var rabbit = MooBot.loadModule('RabbitMQ'); var connection = rabbit.connect({ brokers:[ { host:"myHost", port:5672 } ], user:"test", password:"test", timeout:10000, vhost:"myVHost", ssl:{ ssl_protocol:"TLSv1.2", server_cert_file:"server.pem", client_cert_file:"client.pem", client_key_file:"client.key" } }); if (connection) { connection.send("test", "test", {contentType: "text/xml"}, "<testKey>testValue</testKey>"); connection.send("test", "test", {testKey: "value"}); connection.send("test", "test", ["value"]); connection.send("test", "test", "testValue"); connection.close(); }
var rabbit = MooBot.loadModule('RabbitMQ'); var connection = rabbit.connect({ brokers:[ { host:"rabbithost", port:5672 } ], user:"rabbitmq_admin", password:"78smr9!b", timeout:10000, vhost:"rabbitvhost", ssl:{ ssl_protocol:"TLSv1.2", server_cert_file:"server.pem", client_cert_file:"client.pem", client_key_file:"client.key" } }); if (connection) { connection.send("testExchange", "testRoutingKey", ["one", "two"]); connection.close(); }