Пример #1
0
        /// <summary>
        /// 创建一个单例的RabbitMqClient实例。
        /// </summary>
        /// <returns>IRabbitMqClient</returns>
        public static IRabbitMqClient CreateRabbitMqClientInstance()
        {
            var rabbitMqClientContext = new RabbitMqClientContext
            {
                ListenQueueName = MqConfigDomFactory.CreateConfigDomInstance().MqListenQueueName,
                InstanceCode    = Guid.NewGuid().ToString()
            };

            RabbitMqClient.Instance = new RabbitMqClient
            {
                Context = rabbitMqClientContext
            };
            return(RabbitMqClient.Instance);
        }
        /// <summary>
        /// 根据实例名称获取对应配置
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        internal static RabbitMqClientContext GetContext(string typeName)
        {
            MqConfigDom dom = MqConfigDomFactory.CreateConfigDomInstance(typeName);

            return(new RabbitMqClientContext
            {
                ListenQueueName = dom.MqListenQueueName,
                SendQueueName = dom.MqSendQueueName,
                InstanceCode = Guid.NewGuid().ToString(),
                ListenConnection = CreateListenConnection(dom),
                SendConnection = CreateSendConnection(dom),
                mqConfigDom = dom
            });
        }
Пример #3
0
        /// <summary>
        /// 创建一个IConnection。
        /// </summary>
        /// <returns></returns>
        internal static IConnection CreateConnection()
        {
            var mqConfigDom = MqConfigDomFactory.CreateConfigDomInstance(); //获取MQ的配置

            const ushort heartbeat = 60;
            var          factory   = new ConnectionFactory()
            {
                HostName                 = mqConfigDom.MqHost,
                UserName                 = mqConfigDom.MqUserName,
                Password                 = mqConfigDom.MqPassword,
                RequestedHeartbeat       = heartbeat, //心跳超时时间
                AutomaticRecoveryEnabled = true       //自动重连
            };

            return(factory.CreateConnection()); //创建连接对象
        }
Пример #4
0
        private static void SendEventMessage()
        {
            var originObject = new UpdatePurchaseOrderStatusByBillIdMqContract()
            {
                UpdatePurchaseOrderStatusType = 1,
                RelationBillType = 10,
                RelationBillId   = 10016779,
                UpdateStatus     = 30,
                ModifiedBy       = 11
            };

            var sendMessage        = EventMessageFactory.CreateEventMessageInstance(originObject, MessageTypeConst.ZgUpdatePurchaseStatus);
            var mqConfigDomFactory = MqConfigDomFactory.CreateConfigDomInstance();

            RabbitMqClient.Instance.TriggerEventMessage(sendMessage, mqConfigDomFactory.MqExchangeName, mqConfigDomFactory.MqListenQueueName);
            Console.WriteLine(11);
        }
        /// <summary>
        /// 创建一个单例的RabbitMqClient实例。
        /// </summary>
        /// <returns>IRabbitMqClient</returns>
        public static IRabbitMqClient CreateRabbitMqClientInstance()
        {
            var mqConfig = MqConfigDomFactory.CreateConfigDomInstance();
            var rabbitMqClientContext = new RabbitMqClientContext
            {
                ListenQueueName = mqConfig.MqListenQueueName,
                InstanceCode    = Guid.NewGuid().ToString(),
                ExchangeName    = mqConfig.ExchangeName,
                ExchangeType    = mqConfig.ExchangeType,
                RoutingKey      = mqConfig.RoutingKey
            };

            RabbitMqClient.Instance = new RabbitMqClient
            {
                Context = rabbitMqClientContext
            };

            return(RabbitMqClient.Instance);
        }