Exemple #1
0
 private void Channel_BasicReturn(object sender, RabbitMQ.Client.Events.BasicReturnEventArgs args)
 {
     lock (this)
     {
         string filename        = Path.Combine(_TransactionalMessagePath, string.Format("{0}_{1}.lck", args.RoutingKey, args.BasicProperties.MessageId));
         string messageFilename = Path.ChangeExtension(filename, ".msg");
         if (!File.Exists(messageFilename))
         {
             File.WriteAllBytes(filename, args.Body);
             File.Move(filename, messageFilename);
         }
     }
 }
Exemple #2
0
        private void ModelOnBasicReturn(object sender, BasicReturnEventArgs args)
        {
            DataContractKey dataContractKey = args.BasicProperties.GetDataContractKey();

            Type dataType = _sendHelper.GetDataType(dataContractKey);

            if (dataType == null)
            {
                dataContractKey = DataContractKey.BinaryBlob;
            }

            object data = _configuration.Serializer.Deserialize(dataContractKey, dataType, args.Body);

            RawBusMessage message = _messageHelper.ConstructMessage(dataContractKey, args.BasicProperties, data);

            OnMessageReturn(args.ReplyCode, args.ReplyText, message);
        }
Exemple #3
0
 protected void ModelOnBasicReturn(object model, BasicReturnEventArgs e)
 {
     eventBus.Publish(new ReturnedMessageEvent(e.Body,
         new MessageProperties(e.BasicProperties),
         new MessageReturnedInfo(e.Exchange, e.RoutingKey, e.ReplyText)));
 }
 /// <summary>
 /// 发现当前消息无法被路由到指定的 queues 中(如果设置了 mandatory 属性,则 broker 会先发送 Channel_BasicReturn)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void Channel_BasicReturn(object sender, RabbitMQ.Client.Events.BasicReturnEventArgs e)
 {
     Console.WriteLine("Channel_BasicReturn");
 }
Exemple #5
0
        public static RequestData Create(BasicReturnEventArgs args )
        {
            Hashtable headers    =   ConvertHeaders(args.BasicProperties.Headers);

            var responseData = new ResponseData()
            {
                ErrorCode       = (RequestData.ErrorCodeEnum)args.ReplyCode,
                ErrorMessage    = args.ReplyText
            };

            var requestData = new RequestData()
            {
                Body = Encoding.UTF8.GetString(args.Body),
                SourceAddress = args.BasicProperties.AppId,
                CorrelationId = args.BasicProperties.CorrelationId,
                Op = (string)headers["op"],
                Data = headers,
                DestAddress = args.RoutingKey,
                Response    =   responseData
            };

            return requestData;
        }
 protected override void OnMessageIsUnrouted(IModel model, BasicReturnEventArgs args)
 {
     OnMessageIsUnroutedIsCall = true;
 }
 public virtual void OnBasicReturn(BasicReturnEventArgs args)
 {
     BasicReturnEventHandler handler;
     lock (m_eventLock)
     {
         handler = m_basicReturn;
     }
     if (handler != null)
     {
         foreach (BasicReturnEventHandler h in handler.GetInvocationList()) {
             try {
                 h(this, args);
             } catch (Exception e) {
                 CallbackExceptionEventArgs exnArgs = new CallbackExceptionEventArgs(e);
                 exnArgs.Detail["context"] = "OnBasicReturn";
                 OnCallbackException(exnArgs);
             }
         }
     }
 }
 void OnBasicReturn(object model, BasicReturnEventArgs args)
 {
     if (_log.IsDebugEnabled)
         _log.DebugFormat("BasicReturn: {0}-{1} {2}", args.ReplyCode, args.ReplyText, args.BasicProperties.MessageId);
 }
Exemple #9
0
 protected virtual void OnModelBasicReturn(Object sender, BasicReturnEventArgs args) { }
Exemple #10
0
 private void PublishModelOnBasicReturn(IModel model, BasicReturnEventArgs args)
 {
     // beware, this is called on the RabbitMQ client connection thread, we should not block
     //log.DebugFormat("Model issued a basic return for message {{we can do better here}} with reply {0} - {1}", args.ReplyCode, args.ReplyText);
     basicReturnHandler.Handle(new BasicReturn(new RogerGuid(args.BasicProperties.MessageId), args.ReplyCode, args.ReplyText));
 }
 private void OnMessageReturnedFromBroker(object sender, BasicReturnEventArgs args)
 {
     Log.Error("Message returned from exchange '{1}'", args.Exchange);
 }
Exemple #12
0
        protected override void OnModelBasicReturn(Object sender, BasicReturnEventArgs args)
        {
            base.OnModelBasicReturn(sender, args);

            _log.Info($"consumer-model basic.return received (reply-text: '{args.ReplyText}', reply-code: {args.ReplyCode})");
        }
 private void ModelOnBasicReturn(object sender, BasicReturnEventArgs e)
 {
     _logger.Debug(
         $"Return, code: {e.ReplyCode}, message: {e.ReplyText},  message id:{e.BasicProperties.MessageId}");
     Return?.Invoke(this, e);
 }
Exemple #14
0
 public static ResponseData FromBasicReturn(BasicReturnEventArgs args)
 {
     ResponseData response       = new ResponseData();
     response.DestinationAddress =   args.RoutingKey;
     response.Exchange       =       args.Exchange;
     response.Value          =       args.ReplyCode;
     response.ErrorCode      =       RequestData.ErrorCodeEnum.BusSpecificError;
     response.ErrorMessage   =       args.ReplyText;
     response.Data           =       RMQBus.ConvertHeaders(args.BasicProperties.Headers);
     response.Body           =       RMQBus.GetBodyString(args.Body);
     response.CorrelationId  =       args.BasicProperties.CorrelationId;
     return response;
 }
		private	void ModelOnBasicReturn(object sender, BasicReturnEventArgs	args)
		{
			if (LogAdapter.LogEnabled)
			{
				LogAdapter.LogDebug("RabbitChannel", 
					"Message dropped. Message sent to exchange " + args.Exchange + " with routing key "	+ args.RoutingKey, 
					null);
			}

			var	ev = this.MessageUnrouted;
			if (ev == null)	return;

			var	envelope = new MessageEnvelope(args.BasicProperties, args.Body);
			var	eventArgs =	new	MessageUnroutedEventArgs()
			{
				MessageEnvelope	= envelope,
				Exchange = args.Exchange,
				ReplyCode =	args.ReplyCode,
				ReplyText =	args.ReplyText,
				RoutingKey = args.RoutingKey
			};
				
			ev(eventArgs);
		}
 public virtual void OnBasicReturn(BasicReturnEventArgs args)
 {
     EventHandler<BasicReturnEventArgs> handler;
     lock (m_eventLock)
     {
         handler = m_basicReturn;
     }
     if (handler != null)
     {
         foreach (EventHandler<BasicReturnEventArgs> h in handler.GetInvocationList())
         {
             try
             {
                 h(this, args);
             }
             catch (Exception e)
             {
                 OnCallbackException(CallbackExceptionEventArgs.Build(e, "OnBasicReturn"));
             }
         }
     }
 }
Exemple #17
0
 private void BasicReturnEventHandler(object sender, BasicReturnEventArgs e)
 {
     this.BasicReturn?.Invoke(sender, e);
 }
 public virtual void OnBasicReturn(BasicReturnEventArgs args)
 {
     m_delegate.OnBasicReturn(args);
 }
 /// <summary>
 /// MANDATORY MODE - BasicReturn is invoked when there is no queue bound to the exchange for published topic.
 /// Sent by broker when mandatory flag is set and there is no queue to route a message, effectively when there is no consumer.
 /// </summary>
 /// <param name="model"></param>
 /// <param name="args"></param>
 protected virtual void Channel_BasicReturn( IModel model, BasicReturnEventArgs args )
 {
     //error code should always be 312
     this.Tracer.TraceEvent ( System.Diagnostics.TraceEventType.Error, 0, "[{0}] bus return error, text: {1}, code: {2}, routing key: {3} ", this, args.ReplyText, args.ReplyCode, args.RoutingKey );
     //if we handle rpc request then we have to release the correlation_id
     if (!string.IsNullOrEmpty(args.BasicProperties.CorrelationId))
     {
         TaskCompletionSource<object> tcs;
         //singnal that there is basic return
         if (Bus.RPCTaskCompletions.TryRemove(args.BasicProperties.CorrelationId, out tcs))
         {
             //fires another thread notifying b.logic
             tcs.SetResult(args);
         }
     }
     else
     {
         //if this is not RPC request then notify client about delivery error by calling handler method OnError
         Process.OnPreError(ResponseData.FromBasicReturn(args));
     }
 }
        void OnBasicReturn(object model, BasicReturnEventArgs args)
        {
            if (_log.IsDebugEnabled)
                _log.DebugFormat("BasicReturn: {0}-{1} {2}", args.ReplyCode, args.ReplyText, args.BasicProperties.MessageId);

            object value;
            if (args.BasicProperties.Headers.TryGetValue("publishId", out value))
            {
                var bytes = value as byte[];
                if (bytes == null)
                    return;

                ulong id;
                if (!ulong.TryParse(Encoding.UTF8.GetString(bytes), out id))
                    return;

                PendingPublish published;
                if (_published.TryRemove(id, out published))
                    published.PublishReturned(args.ReplyCode, args.ReplyText);
            }
        }
 protected override void OnMessageIsUnrouted(object sender, BasicReturnEventArgs args)
 {
     OnMessageIsUnroutedIsCall = true;
 }
 public void HandleBasicReturn(ushort replyCode,
                               string replyText,
                               string exchange,
                               string routingKey,
                               IBasicProperties basicProperties,
                               byte[] body)
 {
     BasicReturnEventArgs e = new BasicReturnEventArgs();
     e.ReplyCode = replyCode;
     e.ReplyText = replyText;
     e.Exchange = exchange;
     e.RoutingKey = routingKey;
     e.BasicProperties = basicProperties;
     e.Body = body;
     OnBasicReturn(e);
 }
 private void OnReturn(object sender, BasicReturnEventArgs args)
 {
     eventBus.Publish(new ReturnedMessageEvent(args.Body,
         new MessageProperties(args.BasicProperties),
         new MessageReturnedInfo(args.Exchange, args.RoutingKey, args.ReplyText)));
 }
 private void ModelOnBasicReturn(object sender, BasicReturnEventArgs args)
 {
     using (Message message = _encoder.ReadMessage(new MemoryStream(args.Body), int.MaxValue))
     {
         _messageProcessor.Process(args.ReplyCode, args.ReplyText, message);
     }
 }
Exemple #25
0
 protected void ModelOnBasicReturn(IModel model, BasicReturnEventArgs args)
 {
     eventBus.Publish(new ReturnedMessageEvent(args.Body,
                                               new MessageProperties(args.BasicProperties),
                                               new MessageReturnedInfo(args.Exchange, args.RoutingKey, args.ReplyText)));
 }