Giter Club home page Giter Club logo

Comments (9)

icebob avatar icebob commented on August 27, 2024

Please create a reproduction code.

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024
// static-service.js
const { ServiceBroker } = require("moleculer");
const ChannelsMiddleware = require("@moleculer/channels").Middleware;
const broker = new ServiceBroker({
  namespace: "test",
  nodeID: "test1",
  transporter: "TCP",
  middlewares:[ChannelsMiddleware({
    adapter:"redis://127.0.0.1:6379"
  })]
});

// Start the Moleculer broker
broker.start();

broker.repl();

setInterval(() => {
  broker.sendToChannel("order.created", {
    id: 1234,
    items: "test"
  });
}, 100);


// Start the service to serve static resources

const serviceSchema = {
  name: "subscriber",
  channels: {
    "order.created": {
      group: "mygroup",
      redis: {
        minIdleTime: 1000,
        claimInterval: 1,
        startID: "0"
      },
      maxRetries: 100,
      handler(payload) {
          console.log(payload);
          throw new Error;
      }
    }
  },
}
broker.createService(serviceSchema).then();

// send 10 times

broker.destroyService("subscriber").then(()=>{
  setTimeout(()=>{
    // then create new Service, Remaining transmission times data loss

broker.createService(serviceSchema);
  }, 10000);
});

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024

How to ensure that data in pending is not lost after destroying the service

from moleculer-channels.

valeeum avatar valeeum commented on August 27, 2024

@putty-kang
The default value for moleculer channels configuration for redis.startID is "$" which means pick up only new messages. You will need to store and manage this value if you want to pick up messages that may have come in while service was down.

From README documentation (https://github.com/moleculerjs/moleculer-channels)
Starting point when consumers fetch data from the consumer group. By default equals to $, i.e., consumers will only see new elements arriving in the stream. More info [here](https://redis.io/commands/XGROUP)

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024

@valeeum I set startID is 0

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024

@icebob

const pubClient = this.clients.get(this.pubName);
// 1. Delete consumer from the consumer group
// 2. Do NOT destroy the consumer group
// https://redis.io/commands/XGROUP
return pubClient.xgroup(
	"DELCONSUMER",
	chan.name, // Stream Name
	chan.group, // Consumer Group
	chan.id // Consumer ID
);

================================================================================

This code results in the loss of unconsumed messages in the reconnecting extension after the service is disconnected

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024

@icebob

You need to first check if there is a message in the ending, and then delete the corresponding consumer

from moleculer-channels.

putty-kang avatar putty-kang commented on August 27, 2024
const pubClient = this.clients.get(this.pubName);
let pending = await pubClient.xpending(
	chan.name,
	chan.group,
	"-",
	"+",
	10 // Max reported entries
);
if(!pending) {
	// 1. Delete consumer from the consumer group
	// 2. Do NOT destroy the consumer group
	// https://redis.io/commands/XGROUP
	return pubClient.xgroup(
		"DELCONSUMER",
		chan.name, // Stream Name
		chan.group, // Consumer Group
		chan.id // Consumer ID
	);
}

from moleculer-channels.

AndreMaz avatar AndreMaz commented on August 27, 2024

Repro example and the proposed fix are here: 8c3eb6e

from moleculer-channels.

Related Issues (20)

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.