public override IMessageQueue GetReplyQueue(Message message) { if (!(Connection.Pattern == MessagePattern.RequestResponse && Connection.Direction == Direction.Inbound)) { throw new InvalidOperationException("Cannot get a reply queue except for inbound request-response"); } return(QueueFactory.Create(message.ResponseConnection)); }
public void TestConsumerSubscribe2() { int n = 0; do { IConsumer consumer = QueueFactory <IConsumer> .Create(); consumer.Subscribe(new Action <MqMessageModel>(ConsumeEvent)); Thread.Sleep(500); } while (n < 5); states[3] = true; }
public void TestProducer() { IProducer producer = QueueFactory <IProducer> .Create(); int count = 0; do { producer.Publish(new MqMessageModel() { Content = string.Format(message, "MqMessageModel " + count) }); count++; Thread.Sleep(500); }while (count <= 10); states[0] = true; }
public override IMessageQueue GetResponseQueue() { if (!(Connection.Pattern == MessagePattern.RequestResponse && Connection.Direction == Direction.Outbound)) { throw new InvalidOperationException("Cannot get a response queue except for outbound request-response"); } if (ResponseQueue != null) { return(ResponseQueue); } // make unique based on timestamp and guid var address = $".\\private$\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}:{Guid.NewGuid().ToString().Trim('{','}')}"; var connection = new MessageQueueConnection { Address = address, Pattern = MessagePattern.RequestResponse, Direction = Direction.Inbound }; ResponseQueue = QueueFactory.Create(connection); return(ResponseQueue); }
public override IMessageQueue GetResponseQueue() { if (!(Connection.Pattern == MessagePattern.RequestResponse && Connection.Direction == Direction.Outbound)) { throw new InvalidOperationException("Cannot get a response queue except for outbound request-response"); } if (ResponseQueue != null) { return(ResponseQueue); } var queueName = $"{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-{Guid.NewGuid().ToString("D")}"; var connection = new AzureMessageQueueConnection { Name = queueName, Endpoint = AzureConnection.Endpoint, Direction = Direction.Inbound, Pattern = MessagePattern.RequestResponse }; ResponseQueue = QueueFactory.Create(connection); return(ResponseQueue); }
/// <summary> /// 根据配置创建消费者 /// </summary> /// <param name="itemKey"></param> private void RunFactory(MqConsumerItemKey itemKey) { //pull 方式消费消息 var configModel = TaskList.First(t => t.Exchange == itemKey.Exchange && t.RoutingKey == itemKey.RoutingKey && t.QueueName == itemKey.QueueName); if (configModel.MqMessageType == 0) { Thread th = new Thread(() => ParameterizedThreadStart(itemKey)); th.Name = string.Format("{0}-{1}-{2}", itemKey.Exchange, itemKey.RoutingKey, itemKey.QueueName); th.IsBackground = true; threadList.Add(th); } //sub 方式消费消息 else { var consumer = QueueFactory <IConsumer> .Create(); consumer.Subscribe(itemKey.Exchange, itemKey.QueueName, itemKey.RoutingKey, configModel.IsProperties, MqMessageExecute, false); Consumers.Add(consumer); } }
private void ParameterizedThreadStart(MqConsumerItemKey mqItemKey) { var configModel = TaskList.FirstOrDefault(t => t.Exchange == mqItemKey.Exchange && t.RoutingKey == mqItemKey.RoutingKey && t.QueueName == mqItemKey.QueueName); //创建一个消费者 if (configModel.IsNull()) { //记录日志 LogHelper.LogInfo(logSource, string.Format("ParameterizedThreadStart 配置PULL方式消费者未找到业务配置: {0};{1};{2}", mqItemKey.Exchange, mqItemKey.RoutingKey, mqItemKey.QueueName)); return; } var Consumer = QueueFactory <IConsumer> .Create(); Consumers.Add(Consumer); if (configModel.MqMessageType == 0) { do { Consumer.Pull(mqItemKey.Exchange, mqItemKey.QueueName, mqItemKey.RoutingKey, MqMessageExecute); var timeInterval = configModel.TimeInterval == 0 ? 10 : configModel.TimeInterval; Thread.CurrentThread.Join(timeInterval); }while (true); } }
public override IMessageQueue GetReplyQueue(Message message) => QueueFactory.Create(message.ResponseConnection);