0.0.29 • Published 8 months ago

rsocket-broker-client-js v0.0.29

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

rsocket-broker-client-js

RSocket Broker Client for JavaScript, to be used in conjunction with rsocket-broker

Installation

npm install rsocket-broker-client-js

required running broker instance and target service

todo: add docker-compose file for running broker and target service

Features

  • Request/Response
  • Request/Stream
  • Fire/And/Forget
  • Metadata
  • Request/Channel
  • Responders

Usage

/* instance of RSocket-broker-client 
    (maybe define or wrap into service) */
const rsocket-broker-client = new RsocketBrokerClient();

/* create a new broker client id */
const id = new BrokerClientId();

/* create client connection properties */
const connectionProperties: ConnectionProperties = {
  token: 'AValidJWTToken',
  brokerUrl: 'ws://localhost:7171',
  brokerClientId: id,
  brokerClientName: 'angularBrokerClient',
  connectionTags: new Tags(),
};

const rsocket = await this.rsocket-broker-client.connect(connectionProperties);

/*  
    data to send to target destination function, 
    dummyData in this sample assumes same type is returned, 
    but obviously would depend on function call. 
    This is just to show how to send data to target function
*/

const dummyData = new DummyData();
dummyData.value = 'test';

/* 
    address tags are used to route to target function, 
    in this sample we are using the same tags as the target function
    Available RoutingTypes UNICAST, MULTICAST, SHARD
    The latter is untested.
*/
const requestProperties: RequestProperties = {
  payload:  Buffer.from(dummyData.toPayloadString()),
  brokerClientId: id,
  route: 'targetFunctionName',
  brokerTargetName: 'targetServiceName',
  addressTags: addressTags,
  addressMetadataTags: new Tags(),
  flags: BrokerRoutingType.UNICAST,
};  

/* 
    send request/responsestream to target function
    metadata is not optional
*/
const metadata=  this.rsocket-broker-client.addMetadata(requestProperties.token, requestProperties.brokerClientId, requestProperties.route, requestProperties.addressMetadataTags, requestProperties.addressTags, requestProperties.flags)
const response = await this.rsocket-broker-client.requestStream(rsocket, dummyData.toPayloadString(), metadata);
response.subscribe({
    next: (payload: string) => {
      const dummyData = new DummyData();
      dummyData.fromPayloadString(payload);
      console.log(dummyData);
    },
    error: (error: Error) => { console.log(error); },
    complete: () => { console.log('complete'); },
});

Building

Run nx build rsocket-broker-client-js to build the library.

Running unit tests

Run nx test rsocket-broker-client-js to execute the unit tests via Jest.

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

9 months ago

0.0.26

9 months ago

0.0.25

9 months ago

0.0.24

9 months ago

0.0.23

9 months ago

0.0.22

9 months ago

0.0.21

9 months ago

0.0.20

9 months ago

0.0.19

9 months ago

0.0.18

9 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago