Search

Chapter 5. Using the API

download PDF

For more information, see the Rhea API reference, Rhea example suite and Rhea examples.

5.1. Handling messaging events

Red Hat build of Rhea is an asynchronous event-driven API. To define how the application handles events, the user registers event-handling functions on the container object. These functions are then called as network activity or timers trigger new events.

Example: Handling messaging events

var rhea = require("rhea");
var container = rhea.create_container();

container.on("sendable", function (event) {
    console.log("A message can be sent");
});

container.on("message", function (event) {
    console.log("A message is received");
});

These are only a few common-case events. The full set is documented in the Rhea API reference.

5.3. Creating a container

The container is the top-level API object. It is the entry point for creating connections, and it is responsible for running the main event loop. It is often constructed with a global event handler.

Example: Creating a container

var rhea = require("rhea");
var container = rhea.create_container();

5.4. Setting the container identity

Each container instance has a unique identity called the container ID. When Red Hat build of Rhea makes a network connection, it sends the container ID to the remote peer. To set the container ID, pass the id option to the create_container method.

Example: Setting the container identity

var container = rhea.create_container({id: "job-processor-3"});

If the user does not set the ID, the library will generate a UUID when the container is constructed.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.