npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@triact/message-bus.core

v0.1.2-alpha.3

Published

Easy messaging library to send/publish and handle messages. Build in support for AWS SQS/SNS as transport.

Downloads

11

Readme

message-bus

Easy messaging library to send/publish and handle messages. Build in support for AWS SQS/SNS as transport.

Extendable on the following components:

  • Transport
  • Logging

Installing

Using npm:

npm install @triact/message-bus.core

Creating an endpoint

Endpoint is the entry point of the framework. You first create an endpoint with an unique name. And endpoint can be started (both message sending/publishing and handling) as weel as sendOnly (only message sending).

import { Endpoint, FakeTransport, ConsoleLogger } from '@triact/message-bus.core';

let endpoint = new Endpoint('my-endpoint');

// optional: configure custom inversify container used for dependency injection registry
//endpoint.useExistingContainer(container);

// configure logger. ConsoleLogger is enabled by default.
//endpoint.useLogger<ConsoleLogger>(ConsoleLogger);

// configure the transport of your choise. Default FakeTransport is configured for testing purposes.
endpoint.useTransport<FakeTransport>(FakeTransport, transport => {
    // configure the transport here.
    //transport.
}); 

// configure routes for outgoing messages
endpoint.routes(routing => {
    // destination for outgoing commands
    routing.routeToEndpoint<MyCommand>(MyCommand, 'destination-queue-name');
    // destination for events 
    routing.routeToTopic<MyEvent>(MyEvent, 'destination-topic-name');
});

// configure message handlers. Message to handle can be both a command of event.
endpoint.handlers(handling => {
    handling.handleMessages<MyCommand>(MyCommand, MyMessageHandler);
});

// Customizations in the DI container
endpoint.customize(container => {
    //container.bind(Symbol.for('MyService')).to(MyService);
});

// start endpoint with message handling enabled, or start without message handling
let bus = endpoint.start();
//let bus = endpoint.sendOnly();

Transports

AmazonTransport

Install the amazon sdk.

npm install aws-sdk

The name of the endpoint will be used as incoming queue name in SQS.

const awsCredentials = new AWS.SharedIniFileCredentials({ profile: 'my-profile' });
const awsConfig = new AWS.Config();
awsConfig.update({
    credentials: awsCredentials,
    region: 'eu-west-1'
});

endpoint.useTransport<AmazonTransport>(AmazonTransport, transport => {
    let awsAccountId = '123456789';
    transport.awsConfig(awsConfig, awsAccountId);
});

Creating a custom transport

Docs coming soon

Creating Messages

Command

import { command } from '@triact/message-bus.core';

// Decorate with the command decorator and provide a system global unique identier to uniquely identify the command in the system.
@command(Symbol.for('MyCommand'))
export class MyCommand {
    value: string = '';
}

Event

import { event } from '@triact/message-bus.core';

// Decorate with the event decorator and provide a system global unique name of the event to uniquely identify the event in the system.
@event(Symbol.for('MyEvent'))
export class MyEvent {
    value: string = '';
}

Creating Handlers

Create a new class and implement interface IHandleMessages<T>

import { interfaces } from '@triact/message-bus.core';
import { MyCommand } from '../messages/commands/MyCommand';

export class MyMessageHandler implements interfaces.IHandleMessages<MyCommand> {
    handle = async (msg: MyCommand, context: interfaces.IMessageContext) => {
        console.log(`Handle your message here. value=${msg.value}`);
    }
}