예제 #1
0
        public void Publish(long mallID, string eventType = "user_view_card", string msg = "")
        {
            var routeKey = string.Format(_KeyFormat, eventType, mallID);

            var b = _RabbitClient.Publish(msg, routeKey, _ExChange);

            Console.WriteLine("Publish msg:{0} ex:{1} k:{2} result:{3}", msg, _ExChange, routeKey, b);
        }
예제 #2
0
        public void SetPower(byte power)
        {
            var milliseconds = (DateTime.UtcNow - new DateTime(1970, 1, 1)).Milliseconds;
            var powerMessage = new PowerMessage()
            {
                AccessCode = accessCode, P = power, TeamId = teamName, TimeStamp = milliseconds
            };

            var message = serializer.Serialize(powerMessage);

            lock (powerLock)
            {
                client.Publish(teamName, RoutingKeyNames.Power, message);
            }
        }
예제 #3
0
        public void Test_SubscribeAndPublish()
        {
            _rabbitClient.Publish(
                new TestMessage()
            {
                Name = $"当前时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"
            },
                config =>
            {
                config.PlanPublishTime = DateTime.Now.AddSeconds(1);
            });

            _rabbitClient.Subscribe <TestMessage>(
                async(message, context) =>
            {
                Console.WriteLine(message.Name);
                await Task.FromResult(0);
            });

            Thread.Sleep(3000);
        }