How to use rhea - 10 common examples

To help you get started, we’ve selected a few rhea examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github n8n-io / n8n / packages / nodes-base / nodes / Amqp / AmqpTrigger.node.ts View on Github external
container.options.password = credentials.password;
		}

		let lastMsgId: number | undefined = undefined;
		const self = this;

		container.on('message', (context: any) => { // tslint:disable-line:no-any
			if (context.message.message_id && context.message.message_id === lastMsgId) {
				// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
				lastMsgId = context.message.message_id;
				return;
			}
			self.emit([self.helpers.returnJsonArray([context.message])]);
		});

		const connection = container.connect(connectOptions);
		let clientOptions = undefined;
		if (durable) {
			clientOptions = {
				name: subscription,
				source: {
					address: sink,
					durable: 2,
					expiry_policy: 'never'
				},
				credit_window: 1	// prefetch 1
			};
		} else {
			clientOptions = {
				source: {
					address: sink,
				},
github amqp / rhea / examples / tls / tls_server.js View on Github external
var fs = require('fs');
var path = require('path');
var args = require('../options.js').options({
    'p': { alias: 'port', default: 5671, describe: 'port to listen on'}
}).help('help').argv;

container.on('connection_open', function (context) {
    var cert = context.connection.get_peer_certificate();
    var cn;
    if (cert && cert.subject) cn = cert.subject.CN;
    var tls = context.connection.get_tls_socket();
    var servername;
    if (tls && tls.servername) servername = tls.servername;
    console.log('Connected: ' + cn + ((tls && tls.servername) ? ' [' + tls.servername + ']' : ''));
});
var listener = container.listen({port:args.port, transport:'tls',
    //enable_sasl_external:true,
    key: fs.readFileSync(path.resolve(__dirname, 'server-key.pem')),
    cert: fs.readFileSync(path.resolve(__dirname,'server-cert.pem')),

    // to require client authentication:
    requestCert: true,
    rejectUnauthorized: true,
    ca: [ fs.readFileSync(path.resolve(__dirname,'ca-cert.pem')) ]
});
listener.on('clientError', function (error, socket) {
    console.log(error);
});
github amqp / rhea / examples / direct_recv.js View on Github external
* distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var container = require('rhea');

var args = require('./options.js').options({
    'm': { alias: 'messages', default: 100, describe: 'number of messages to expect'},
    'p': { alias: 'port', default: 8888, describe: 'port to connect to'}
}).help('help').argv;

var received = 0;
var expected = args.messages;

var server = container.listen({ port: args.port });

container.on('message', function (context) {
    if (context.message.id && context.message.id < received) {
        // ignore duplicate message
        return;
    }
    if (expected === 0 || received < expected) {
        console.log(context.message.body);
        if (++received === expected) {
            context.receiver.detach();
            context.connection.close();
            server.close();
        }
    }
});
github EnMasseProject / enmasse / agent / lib / auth_utils.js View on Github external
.catch((error) => {
                        console.error('OpenID Connect  Error', error);
                        response.status(500).end('Authentication failed');
                    }).finally(() => {
                        remove_from_session(request, "openid");
                        remove_from_session(request, "state");
                        remove_from_session(request, "saved_request_url");
                        remove_from_session(request, "saved_redirect_url");
                });
            } else {
                const client = new auth_context.Client({
                    client_id: env.CONSOLE_OAUTH_CLIENT_ID,
                    client_secret: env.CONSOLE_OAUTH_CLIENT_SECRET,
                });

                let state = rhea.generate_uuid();
                let redirect_uri = request.protocol + "://" + request.headers.host + "/authcallback";
                store_in_session(request, "openid", client);
                store_in_session(request, "state", state);
                store_in_session(request, "saved_request_url", request.url);
                store_in_session(request, "saved_redirect_url", redirect_uri);

                const authorization_url = client.authorizationUrl({
                    redirect_uri: redirect_uri,
                    scope: env.CONSOLE_OAUTH_SCOPE,
                    state: state,
                    response_type: 'code'
                });

                // redirect
                response.redirect(authorization_url)
            }
github EnMasseProject / enmasse / agent / lib / auth_utils.js View on Github external
const credentials = {
                        client: {
                            id: env.CONSOLE_OAUTH_CLIENT_ID,
                            secret: env.CONSOLE_OAUTH_CLIENT_SECRET,
                        },
                        auth: {
                            tokenHost: auth_context.issuer,
                            authorizePath: auth_context.authorization_endpoint,
                            tokenPath: auth_context.token_endpoint,
                        },
                        options: {
                            authorizationMethod: 'body'
                        },
                    };

                    let state = rhea.generate_uuid();
                    let oauth2 = oauth2_factory.create(credentials);
                    let redirect_uri = request.protocol + "://" + request.headers.host + "/authcallback";
                    store_in_session(request, "oauth2", oauth2);
                    store_in_session(request, "saved_request_url", request.url);
                    store_in_session(request, "saved_redirect_url", redirect_uri);

                    const authorization_url = oauth2.authorizationCode.authorizeURL({
                        redirect_uri: redirect_uri,
                        scope: env.CONSOLE_OAUTH_SCOPE,
                        state: state
                    });

                    // redirect
                    response.redirect(authorization_url)
                } catch (error) {
                    console.error('Authorization Error', error.message);
github n8n-io / n8n / packages / nodes-base / nodes / Amqp / AmqpTrigger.node.ts View on Github external
}
		let durable = false;
		if(subscription && clientname) {
			durable = true;
		}

		const container = require('rhea');
		const connectOptions: ContainerOptions = {
			host: credentials.hostname,
			port: credentials.port,
			reconnect: true,		// this id the default anyway
			reconnect_limit: 50,	// try for max 50 times, based on a back-off algorithm
			container_id: (durable ? clientname : null)
		};
		if (credentials.username || credentials.password) {
			container.options.username = credentials.username;
			container.options.password = credentials.password;
		}

		let lastMsgId: number | undefined = undefined;
		const self = this;

		container.on('message', (context: any) => { // tslint:disable-line:no-any
			if (context.message.message_id && context.message.message_id === lastMsgId) {
				// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
				lastMsgId = context.message.message_id;
				return;
			}
			self.emit([self.helpers.returnJsonArray([context.message])]);
		});

		const connection = container.connect(connectOptions);
github n8n-io / n8n / packages / nodes-base / nodes / Amqp / AmqpTrigger.node.ts View on Github external
let durable = false;
		if(subscription && clientname) {
			durable = true;
		}

		const container = require('rhea');
		const connectOptions: ContainerOptions = {
			host: credentials.hostname,
			port: credentials.port,
			reconnect: true,		// this id the default anyway
			reconnect_limit: 50,	// try for max 50 times, based on a back-off algorithm
			container_id: (durable ? clientname : null)
		};
		if (credentials.username || credentials.password) {
			container.options.username = credentials.username;
			container.options.password = credentials.password;
		}

		let lastMsgId: number | undefined = undefined;
		const self = this;

		container.on('message', (context: any) => { // tslint:disable-line:no-any
			if (context.message.message_id && context.message.message_id === lastMsgId) {
				// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
				lastMsgId = context.message.message_id;
				return;
			}
			self.emit([self.helpers.returnJsonArray([context.message])]);
		});

		const connection = container.connect(connectOptions);
		let clientOptions = undefined;
github Azure / azure-event-hubs-node / dist / lib / eventHubSender.js View on Github external
}
                if (!this._isOpen()) {
                    debug("Acquiring lock %s for initializing the session, sender and " +
                        "possibly the connection.", this.senderLock);
                    yield utils_1.defaultLock.acquire(this.senderLock, () => { return this._init(); });
                }
                debug("[%s] Sender '%s', trying to send EventData[]: %O", this._context.connectionId, this.name, datas);
                const messages = [];
                // Convert EventData to AmqpMessage.
                for (let i = 0; i < datas.length; i++) {
                    const message = eventData_1.EventData.toAmqpMessage(datas[i]);
                    messages[i] = message;
                }
                // Encode every amqp message and then convert every encoded message to amqp data section
                const batchMessage = {
                    body: rhea.message.data_sections(messages.map(rhea.message.encode))
                };
                // Set message_annotations, application_properties and properties of the first message as
                // that of the envelope (batch message).
                if (messages[0].message_annotations) {
                    batchMessage.message_annotations = messages[0].message_annotations;
                }
                if (messages[0].application_properties) {
                    batchMessage.application_properties = messages[0].application_properties;
                }
                for (const prop of eventData_1.messageProperties) {
                    if (messages[0][prop]) {
                        batchMessage[prop] = messages[0][prop];
                    }
                }
                // Finally encode the envelope (batch message).
                const encodedBatchMessage = rhea.message.encode(batchMessage);
github amqp / rhea / examples / selector / recv.js View on Github external
container.on('message', function (context) {
    if (context.message.properties && context.message.properties.id && context.message.properties.id < received) {
        // ignore duplicate message
        return;
    }
    if (expected === 0 || received < expected) {
        console.log(context.message.body);
        if (++received === expected) {
            context.receiver.detach();
            context.connection.close();
        }
    }
});

container.connect({ port: args.port, host: args.host }).open_receiver({source:{address:args.node, filter:filters.selector(args.selector)}});
github apache / qpid-dispatch / console / react / src / amqp / connection.js View on Github external
var sendable = function (context) {
          clearTimeout(timer);
          this.version = this.connection.properties
            ? this.connection.properties.version
            : "0.1.0";
          // in case this connection dies
          rhea.on("disconnected", this.on_disconnected);
          // in case this connection dies and is then reconnected automatically
          rhea.on("connection_open", this.on_connection_open);
          // receive messages here
          this.connection.on("message", this.on_message);
          resolve(context);
        }.bind(this);
        this.connection.once("sendable", sendable);