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

payment-microservice-client

v2.1.0

Published

Package to create a socket interface with redis ready to connect to a microservice using payment-microservice package.

Downloads

63

Readme

Payment Microservice Client

Description

Application side package for payment-microservice.

This package is meant to be a wrapper for applications using the payment-microservice package with redis.

Usage

Import the package main method:

import pmClient from 'payment-microservice-client';

This method will receive either the express server and the port in which it is running to start a socket server and client on it, or if you already have a socket server you can pass it to the function and it will use it.

If both the socket server and the express server are passed, the socket server will be used and the express server will be ignored.

Returns the socketServer.

Parameters

| Parameter | Type | Description | Optional | | ------------ | ---------------------------------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------- | | httpServer | http.Server | Express server | Yes. Only needed if no socketServer is passed. | | httpPort | number | Por in which the socket client will run. Should be the same as the express server port. | No. | | socketServer | io.Server | Socket server which will be used to set up the connection. | Yes. Only needed if no httpServer and httpPort are passed | | redisPort | number | Port in which the redis server is running . | No | | socketPath | string | Path in which the socket server will be running. Defaults to /ws | Yes. Only needed if no socketServer is passed. | | redisHost | string | Path or IP for the redis server | No | | clientName | string | Application name for this client. Used for logging. | No | | connectFn | function. (socket: io.Socket) => void) | Function which will be executed on the on connection event of the socket server. | Yes |

Example:


const app = express();
  app.use(cors());
  const server = createServer(app);
  server.listen(3005);
  pmClient({
    httpServer: server,
    httpPort: 3005,
    socketPath: '/ws',
    redisHost: '127.0.0.1',
    clientName: 'TestClient',
    connectFn: socketConnect,
  });
  const socketConnect = (socket: Socket): void => {...}

This method will create a socket server (if not passed) with a redisAdapter, and a socket client.

The socket client will connect to its own server, which will push it into a room with name hostName().

This socket client will listen to the alive event emmited by the payment-microservice package. This event will receive an object with a micro service name and a room name, which will be pushed into an array.

Socket interface

This package exposes a socket interface to communicate with the micro services.

To do this we will use the executeToRoom method.

const executeToRoom = <ReturnType>(
  name: string,
  params?: object,
  microName?: string,
): Promise<ReturnType> => {...}

This method will make a synchronous call to a micro service socket event. It receives the name of the event, the params for the event method and the micro service name.

It will take the most recent room in the array with the micro service name passed and will execute the event, which has been set with a methodWrapper from the payment-microservice package. When the micro service method ends its execution it will emit an event with an id supplied by executeToRoom, which will be listening for this event and resolve the promise.

If our application is only communicating with one micro service, we don't need to use the microName param, as it will take the most recent room from the array.

Example:

import Socket from 'payment-microservice-client/Socket';
const keys = await Socket.executeToRoom<string>('getKeys', inData, 'PayPal');