GithubHelp home page GithubHelp logo

avencera / moleculer-rs Goto Github PK

View Code? Open in Web Editor NEW
19.0 4.0 4.0 333 KB

๐Ÿš€ Progressive microservices framework for Rust, based on and compatible with moleculerjs/moleculer

License: Apache License 2.0

Rust 100.00%
moleculer microservices microservice-framework

moleculer-rs's People

Contributors

praveenperera avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

moleculer-rs's Issues

Implement receiving actions and sending response [Host]

//[PUB MOL.REQ.praveensmacbookpro.local-39536 311]
request =  {
   "action": "greeter.welcome",
   "caller": nil,
   "id": "f880a296-67cc-4c2d-857c-b015cf875dac",
   "level": 1,
   "meta": {"$repl": true},
   "params": {"name": "Praveen"},
   "parentID": nil,
   "requestID": "f880a296-67cc-4c2d-857c-b015cf875dac",
   "sender": "cli-praveensmacbookpro.local-39040",
   "stream": false,
   "timeout": 0,
   "tracing": nil,
   "ver": "4"
 }
// [PUB MOL.RES.cli-praveensmacbookpro.local-39040 160]
response =  
{
   "data": "Welcome, Praveen",
   "id": "f880a296-67cc-4c2d-857c-b015cf875dac",
   "meta": {"$repl": true},
   "sender": "praveensmacbookpro.local-39536",
   "success": true,
   "ver": "4"
 }

Context properties

Hey, I am just trying to port (I guess) some moleculer service from Javascript, granted I know just a basics in Rust and in general I am below the 10k lines ever written, so pardon if the question is stupid.

However in the moleculer-js, you can assing certain parameters to context
https://moleculer.services/docs/0.14/context.html

it does not appear to be the case in your Rust implementation, I know that due to borrow checker, this might not be possible, especially with tokio threading.

But I would still like to ask if I could get some assistance how to do this:

I have this piece of code:

broker.createService({
  name: config.id,
  mixins: [Request],
  dependencies: ['blockchainRegistry', 'paymentGateway'],
  events: {
    ping: {
      handler(ctx) {
        const nowTime = new Date().getTime();
        const delay = nowTime - ctx.params.datetime;
        return ctx.broadcast('pong', { service_prefix: ctx.name, datetime: nowTime, delay });
      },
    },
    "currency.created": {
      async handler(ctx) {
        ctx.options.coin = await ctx.call('paymentGateway.getPICoin', {paymentInterfaceId: config.id});
      }
    }
  },
  actions,

  created() {
		this.broker.metrics.register({ 
			type: "info", 
			name: "process.converter.version", 
			description: "Converter version", 
		});

		this.broker.metrics.set("process.converter.version", packageJSON.version)
	},
  async started() {
    console.log('STARTED+++++');
    const _self = this;
    
  },
  stopped() {
    console.log("=>>>>>>>>>>>> BROKER STOPPED");
    //broker.call('blockchainRegistry.unregister', {});
  }
});

I figure out most of it, but the currency.created event is beyond my knowledge, since global variables is tricky think to do, do you know any way, how could I store the info, which should go to ctx.options.coin?

Thanks and sorry for being newbie.

Add examples

TODO:

  • Simple Event
  • Async in callback
  • Simple Request/Response
  • Sending action
  • Sending event
  • Receive event and then send event
  • Complex example accessible state outside of callback

Implement protocol v4

Other languages reference: moleculerjs/moleculer#347

Protocol reference: https://github.com/moleculer-framework/protocol/blob/master/4.0/PROTOCOL.md

docs: https://moleculer.services/docs/0.14/configuration.html

implemented in: #9

Easy:

  • Heartbeat MOL.HEARTBEAT
  • Disconnect MOL.DISCONNECT
  • Ping MOL.PING
  • Ping (targeted) MOL.PING.<nodeID>
  • Pong MOL.PONG.<nodeID>

Medium:

  • Discover MOL.DISCOVER
  • Discover (targeted) MOL.DISCOVER.<nodeID>
  • Info MOL.INFO
  • Info (targeted) MOL.INFO.<nodeID>

Later:

  • Request MOL.REQ.<nodeID> #3
  • Response MOL.RES.<nodeID> #3
  • Event MOL.EVENT.<nodeID> #2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.