Beispiel #1
0
 internal void SendToPoisonQueue(RedisValue value)
 {
     if (_publisher == null)
     {
         var redisConnection = (RedisConnection)Container.Connection;
         _publisher = new RedisProducer(redisConnection);
     }
     Log.Warn("Sending message " + value + " to poison letter queue " + PoisonQueue.Name);
     _publisher.Publish(PoisonQueue.Name, value);
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                //// 啟動redis發布訂閱中樞
                RedisFactory.Start(NoSqlService.RedisConnections, NoSqlService.RedisAffixKey, NoSqlService.RedisDataBase);
                ////訂閱關注Topics
                var consumer = new RedisConsumer(ConfigHelper.SubscribTopics, new PubSubDispatcher <RedisEventStream>(AutofacConfig.Container));
                consumer.Register();

                //// 發布事件
                RedisProducer.Publish("A", new AEvent()
                {
                    Message = $"{nameof(AEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
                RedisProducer.Publish("B", new AEvent()
                {
                    Message = $"{nameof(BEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
                RedisProducer.Publish("C", new AEvent()
                {
                    Message = $"{nameof(CEvent)}:{DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}"
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.Read();
        }
Beispiel #3
0
        private void btnSend_Click(object sender, System.EventArgs e)
        {
            using (var redLock = RedisLockHelper.GrabLock(1)) // 有 async 的版本
            {
                // 確定取得 lock 所有權
                if (redLock.IsAcquired)
                {
                    // 執行需要獨佔資源的核心工作
                    RedisProducer.Publish("RedisSample1", new PressureTestContentEvent {
                        Content = "RedisSample1", CreateDateTime = DateTime.Now
                    });
                }
            }

            RedisProducer.Publish("RedisSample2", new PressureTestContentEvent {
                Content = "RedisSample2", CreateDateTime = DateTime.Now
            });

            RedisProducer.Publish("RedisSample3", new PressureTestContentEvent {
                Content = "RedisSample3", CreateDateTime = DateTime.Now
            });
        }