Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context properties #26

Open
M1chlCZ opened this issue May 31, 2023 · 0 comments
Open

Context properties #26

M1chlCZ opened this issue May 31, 2023 · 0 comments

Comments

@M1chlCZ
Copy link

M1chlCZ commented May 31, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant