0.2.0 • Published 7 months ago

nest-solace-pubsub-transporter v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

nest-solace-pubsub-transporter

NPM version

A Nest microservice transporter for Solace PubSub+

Installation

To begin using it, we first install the required dependency.

$ npm install --save nest-solace-pubsub-transporter solclientjs

Overview

To use the Solace PubSub+ transporter, pass the following options object with a strategy property using SolacePubSubServer to the createMicroservice() method:

const app = await NestFactory.createMicroservice<MicroserviceOptions>(
  AppModule,
  {
    strategy: new SolacePubSubServer({
      url: 'tcp://localhost:55554',
      vpnName: 'default',
      userName: 'admin',
      password: 'admin',
    }),
  },
);

Options

The SolacePubSubServer constructor options object is based on solace.SessionProperties. The Solace PubSub+ transporter exposes the properties described here.

Client

Create an instance of SolacePubSubClient class and run the send() method, subscribing to the returned observable stream.

const client = new SolacePubSubClient({
  url: 'tcp://localhost:55554',
  vpnName: 'default',
  userName: 'admin',
  password: 'admin',
});
client
  .send('pattern', 'Hello world!')
  .subscribe((response) => console.log(response));

To dispatch an event (instead of sending a message), use the emit() method:

solacePubSubClient.emit('event', 'Hello world!');

Context

In more sophisticated scenarios, you may want to access more information about the incoming request. When using the Solace PubSub+ transporter, you can access the SolacePubSubContext object.

@MessagePattern('notifications')
getNotifications(@Payload() data: number[], @Ctx() context: SolacePubSubContext) {
  console.log(`Message: ${context.getMessage()}`);
}

Example

A working example is available here.

License

MIT