示例#1
0
        public void Sub(string topic, Action <string> onMsg)
        {
            _unSub = false;

            var opiton = new ConsumerOptions(topic, _brokerHelper.GetBroker());

            _consumer = new Consumer(opiton);

            Task.Run(() =>
            {
                while (!_unSub)
                {
                    var msgs = _consumer.Consume();
                    Parallel.ForEach(msgs, msg =>
                    {
                        onMsg(Encoding.UTF8.GetString(msg.Value));
                    });
                }
            });
        }
示例#2
0
        public ProduceHelper(BrokerHelper brokerHelper)
        {
            _brokerHelper = brokerHelper;

            _producer = new Producer(_brokerHelper.GetBroker());
        }