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

magicbus-masstransit

v0.1.3

Published

Provides patterns, envelopes, and configuration to make magicbus work with MassTransit 3.0 and above

Downloads

3

Readme

magicbus-masstransit

This aims to support complete interoperation between magicbus and MassTransit 3.5 or greater. That means

  • Automatic creation of exchanges and queues
  • Automatic binding for consumers
  • Message envelope and serialization
  • Send/Consume support
  • Publish/Subscribe support
  • Request/Reply support
  • Routing slip support (as a participant, not as an orchestrator)
  • Scheduling support

Usage

const magicbus = require('magicbus-masstransit')(require('magicbus'));

const broker = magicbus.createBroker('MyDomain', 'AppName', 'amqp://guest:guest@localhost:5672/');

Sending

// analogous to ISendEndpointProvider.GetSendEndpoint()
const sender = magicbus.createSender(broker, 'other-queue');

let sendPromise = sender.send({ some: 'message' });

Consuming

// analogous to ISendEndpointProvider.GetSendEndpoint()
const consumer = magicbus.createConsumer(broker, 'my-queue');

// Creates exchange and queue "my-queue" if they don't exist and binds the exchange to the queue
let consumerStartPromise = consumer.startConsuming((data, types, rawMessage, actions) => {
    return workPromise;
  });

Publishing

const publisher = magicbus.createPublisher(broker);

// Creates exchange "MyDomain.AppName:ProcessStarted" if it doesn't exist
let pubPromise = publisher.publish('ProcessStarted', {
  some: 'data'
});

Subscribing to Events

const subscriber = magicbus.createSubscriber(broker, 'my-subscriber');

subscriber.on('OtherDomain.Some.Namespace:SomeEvent',
  (eventName, data, rawMessage, actions) => {
    // ... do some work
    return workPromise;
  }
);

// Creates exchange and queue "my-subscriber" if they don't exist and binds the exchange to the queue
// Creates exchange "OtherDomain.Some.Namespace:SomeEvent" if it doesn't exist
// Binds exchange "OtherDomain.Some.Namespace:SomeEvent" to exchange "my-subscriber"
let subscriptionStartPromise = subscriber.startSubscription();

Sending a Request/Reply request

const requester = magicbus.createRequester(broker, 'OtherDomain.Some.Namespace:SomeRequest');

// The first request will create a temporary exclusive queue for responses to be directed to.
// Other requests will reuse the same queue
requester.Request({ message: 'PING' })
  .then((response, rawMessage) => {
      // do something with response
    });

Replying to a Request/Reply request

const subscriber = magicbus.createSubscriber(broker, 'my-subscriber');

subscriber.on('MyDomain.AppName:SomeRequest',
  (eventName, data, rawMessage, actions) => {
    // ... do some work
    workPromise.then(() => actions.reply({ message: 'PONG' }));
  });

Implementing a Routing Slip Activity

const endpoint = magicbus.createActivity(broker, 'my-activity-queue', 'my-compensate-queue'); // compensation queue is optional

let endpointStartPromise = endpoint.startEndpoint(
    (arguments, types, rawMessage, actions) => {
      // ... do some work
      return workPromise;
    },
    // compensation function, required when compensation queue is provided, forbidden otherwise
    (log, types, rawMessage, actions) => {
      // ... do some work
      return workPromise;
    }
  );

Scheduling a message

const scheduler = magicbus.createScheduler(broker, 'scheduler-queue');

let later = new Date();
later.setMonth(later.getMonth() + 1);

let scheduledMessagePromise = scheduler.schedulePublish('DoItNow', later, { some: 'data' });

Scheduling a recurring message

const scheduler = magicbus.createScheduler(broker, 'scheduler-queue');

const cronExpression = "* * * * *"; // every minute

let scheduledMessagePromise = scheduler.scheduleRecurringSend('my-queue', scheduler.defaultRecurringSchedule(cronExpression), { some: 'data' });

NOT SUPPORTED

The purpose of this package is to enable javascript services to interoperate with services using MassTransit as their message bus, not to have feature parity with MassTransit. The following features will probably never be implemented in this package.

  • Routing Slip Orchestration - Build a javascript routing slip orchestrator and let me know about it!
  • Sagas - Build a javascript saga orchestrator and let me know about it! magicbus uses machina for its connection state machines.
  • Turnout - Build a javascript long-running task monitor and let me know about it!
  • Circuit Breaker, Retries, or any other message pipeline features from MassTransit or GreenPipes.
    • If you're using magicbus, you've already got most of them! See magicpipes