Code Monkey home page Code Monkey logo

Comments (10)

nnhy avatar nnhy commented on September 20, 2024

consumer孤零零的,过一会gc就该来收割它啦。
可以搞一个数组,把这些消费者对象管理起来

from newlife.rocketmq.

nnhy avatar nnhy commented on September 20, 2024

创建消费者的时候,没有必要异步,直接for循环好了,因为Start只是启动内部线程,并不阻塞

from newlife.rocketmq.

zt72065036 avatar zt72065036 commented on September 20, 2024

consumer孤零零的,过一会gc就该来收割它啦。 可以搞一个数组,把这些消费者对象管理起来

怎么管理呢?定时判断消费者是否存在吗?不存在了就重新创建一个新的?

from newlife.rocketmq.

nnhy avatar nnhy commented on September 20, 2024

弄一个全局变量,或者静态变量都行,只要有引用,GC就不会销毁它

from newlife.rocketmq.

zt72065036 avatar zt72065036 commented on September 20, 2024

弄一个全局变量,或者静态变量都行,只要有引用,GC就不会销毁它

好的,谢谢,另外一个问题,请有可以获取topic下queueid的方法吗?尝试用Queues,好像不行

from newlife.rocketmq.

zt72065036 avatar zt72065036 commented on September 20, 2024

弄一个全局变量,或者静态变量都行,只要有引用,GC就不会销毁它

public static List listConsumer = new List();
public void Start()
{
for (int i = 0; i < 3; i++)
{
var consumer = new Consumer
{
Topic = "bb",
NameServerAddress = "xx",
BatchSize = 3,
Group = "bbgroup"
};
consumer.OnConsume = (q, ms) =>
{
string mInfo = $"datetime={DateTime.Now},BrokerName={q.BrokerName},QueueId={q.QueueId},Length={ms.Length}";
Console.WriteLine(mInfo);
foreach (var item in ms.ToList())
{
string msg = $"消息:msgId={item.MsgId},key={item.Keys},产生时间【{item.BornTimestamp.ToDateTime()}】,内容>{item.BodyString}";
LogHelper.Information("RocketMQConsumer", msg);
}
// return false;//通知消息队:不消费消息
return true; //通知消息队:消费了消息
};
consumer.Start();
listConsumer.Add(consumer);
}
}
这样用listConsumer来管理,还是只会执行一次,麻烦帮看下,谢谢

from newlife.rocketmq.

nnhy avatar nnhy commented on September 20, 2024

嗯,是这样,代码没有错。
可以看看日志。

from newlife.rocketmq.

zt72065036 avatar zt72065036 commented on September 20, 2024

感谢团队大佬贡献

from newlife.rocketmq.

nnhy avatar nnhy commented on September 20, 2024

问题解决了吗?

from newlife.rocketmq.

zt72065036 avatar zt72065036 commented on September 20, 2024

问题解决了吗?

解决了自动回收的问题,但是现在吃内存和CPU很历害,跑一会儿就占内存几G了。

from newlife.rocketmq.

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.