Beispiel #1
0
 public MessageArrivedState(MessageArrivedEventHandler handler, ServiceEventMessage message, MessageQueue queue, AckMessageInfo ackMessageInfo)
 {
     AckMessageInfo = ackMessageInfo;
     Handler        = handler;
     Message        = message;
     Queue          = queue;
 }
            public MessageArrivedState(MessageArrivedEventHandler handler, ServiceEventMessage message,MessageQueue queue, AckMessageInfo ackMessageInfo)
			{
                AckMessageInfo = ackMessageInfo;
				Handler = handler;
				Message = message;
                Queue = queue;
			}
Beispiel #3
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == 0x15)
     {
         MessageArrivedEventHandler messageArrivedEvent = this.MessageArrived;
         if (messageArrivedEvent != null)
         {
             messageArrivedEvent(this, new EventArgs());
         }
     }
     base.WndProc(ref m);
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");
            PiMessage msgProc = new PiMessage();

            MessageArrivedEventHandler allProc = msgProc.ProcessMessage;

            AsynchronousSocketListener listen = new AsynchronousSocketListener(allProc);

            listen.StartListening();
            //listen.SetupThread();
            Console.WriteLine("Done");
        }
 public void Subscribe(bool machineSpecific, string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     CheckRabbitMQ();
     if (machineSpecific)
     {
         queueName = string.Concat(Environment.MachineName, ".", queueName);
     }
     if (temporary)
     {
         queueName = string.Concat(queueName, ".", Guid.NewGuid().ToString());
     }
     _DALRabbitMQ.Subscribe(queueName, durable, temporary, routingKey, handler);
     lock (_Subscriptions)
     {
         _Subscriptions.Add(new Subscription()
         {
             Durable = durable, Handler = handler, QueueName = queueName, RoutingKey = routingKey, Temporary = temporary
         });
     }
 }
 public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     Subscribe(false, queueName, durable, temporary, routingKey, handler);
 }
 public void Subscribe(string queueName, string routingKey, MessageArrivedEventHandler handler)
 {
     Subscribe(false, queueName, true, false, routingKey, handler);
 }
Beispiel #8
0
 public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     for (int index = 0; index < _ServerCount; index++)
     {
         _Subscriptions[index].Subscribe(queueName, durable, temporary, routingKey, handler);
     }
 }
Beispiel #9
0
        private void CallbackHandler(IAsyncResult asyncResult)
        {
            try
            {
                Message    receivedMsg = new Message();
                SqlCommand command     = asyncResult.AsyncState as SqlCommand;
                LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: Started - {0} - {1} - Connection: {2} - {3} ", command.Connection.DataSource, command.Connection.Database, command.Connection.ClientConnectionId.ToString(), command.Connection.State.ToString()));
                command.EndExecuteNonQuery(asyncResult);
                SqlParameter paramMsgType           = command.Parameters["@msgtype"];
                SqlParameter paramMsg               = command.Parameters["@msg"];
                SqlParameter paramConversationGroup = command.Parameters["@cg"];
                SqlParameter paramDialogHandle      = command.Parameters["@dh"];

                if (paramMsgType.Value != DBNull.Value)
                {
                    LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: paramMsgType.Value == {2} - {0} - {1}  - Connection: {3} - {4} ", cnn.DataSource, cnn.Database, paramMsgType.Value, command.Connection.ClientConnectionId.ToString(), command.Connection.State.ToString()));
                    receivedMsg.MessageType    = (string)paramMsgType.Value;
                    receivedMsg.RecivedMessage = (paramMsg.Value == DBNull.Value ? null : paramMsg.Value.ToString());
                    if ((receivedMsg.MessageType == this.reciveMessageType) && receivedMsg.RecivedMessage != null)
                    {
                        LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: paramMsgType.Value OK - {0} - {1} - Connection: {2} - {3} ", cnn.DataSource, cnn.Database, command.Connection.ClientConnectionId.ToString(), command.Connection.State.ToString()));
                        receivedMsg.RecivedXMLMessage  = System.Xml.Linq.XDocument.Parse(receivedMsg.RecivedMessage);
                        receivedMsg.ConversationGroup  = (System.Guid)paramConversationGroup.Value;
                        receivedMsg.ConversationHandle = (System.Guid)paramDialogHandle.Value;
                        string msgType = paramMsgType.Value.ToString();
                        cmd.Cancel();
                        if (this.validator != null && this.validator.Validate <string>(receivedMsg.RecivedMessage))
                        {
                            if (this.dequeueInTransaction && tran != null)
                            {
                                tran.Commit();
                            }
                        }
                        else
                        {
                            if (this.dequeueInTransaction && tran != null)
                            {
                                tran.Rollback();
                            }
                            LoggerUtility.Debug("SVC_ERROR",
                                                (object)string.Format("-  CallbackHandler:: Validator.validate = False !!! - paramMsgType.Value OK - {0} - {1} - Connection: {2} - {3} ",
                                                                      cnn.DataSource, cnn.Database, command.Connection.ClientConnectionId.ToString(), command.Connection.State.ToString()));
                        }
                        cmd.Connection.Close();
                        EndDialog(receivedMsg.ConversationHandle);
                        if (msgType != MESSAGE_TYPE_END_CONVERSATION)
                        {
                            LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: msgType != MESSAGE_TYPE_END_CONVERSATION - {0} - {1}", cnn.DataSource, cnn.Database));
                            MessageArrivedEventHandler handler = MessageArrivedEvent;
                            if (handler != null)
                            {
                                handler(this, new MessageArrivedEventArgs(receivedMsg));
                            }
                        }
                    }
                    else
                    {
                        LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: paramMsgType.Value NOT ALLOWED - {0} - {1}", cnn.DataSource, cnn.Database));

                        if (this.dequeueInTransaction && tran != null)
                        {
                            tran.Commit();
                        }
                        cmd.Cancel();
                        cmd.Connection.Close();
                        Receive();
                    }
                }
                else
                {
                    LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: paramMsgType.Value == DBNull.Value - {0} - {1}", cnn.DataSource, cnn.Database));
                    try
                    {
                        CancelReceive();
                    }
                    catch { }
                    finally
                    {
                        Receive();
                    }
                }

                LoggerUtility.Debug("SVC_DEBUG", (object)string.Format("-  CallbackHandler:: Finished - {0} - {1}", cnn.DataSource, cnn.Database));
            }
            catch (Exception ex)
            {
                LoggerUtility.Error("SVC_ERROR", (object)string.Format("-  CallbackHandler:: ERROR - {0} - {1}", cnn.DataSource, cnn.Database), ex);
                try {
                    if (this.dequeueInTransaction && tran != null)
                    {
                        tran.Rollback();
                    }
                } catch { }
                Receive();
            }
            finally
            {
            }
        }
Beispiel #10
0
 public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     lock (_Queues)
     {
         if (_SubscriptionRequestThread == null)
         {
             _SubscriptionRequestThread = new Thread(new ThreadStart(ProcessSubscriptionRequests));
             if (_SubscriptionRequestThread.Name == null)
             {
                 _SubscriptionRequestThread.Name = "ProcessMQSubscriptionRequests";
             }
             _SubscriptionRequestThread.IsBackground = true;
             _SubscriptionRequestThread.Start();
         }
         if (_Queues.ContainsKey(queueName))
         {
             MessageQueue queue = _Queues[queueName];
             queue.Handlers.Add(handler);
         }
         else
         {
             MessageQueue queue = new MessageQueue();
             queue.Durable     = durable;
             queue.QueueName   = queueName;
             queue.RoutingKey  = routingKey;
             queue.Temporary   = temporary;
             queue.ChannelName = queue.QueueName.Split('.')[0];
             queue.Handlers.Add(handler);
             _Queues.Add(queueName, queue);
             _SubscriptionToAdd.Enqueue(queue);
             _TriggerSubscriptionRequest.Set();
         }
     }
 }
Beispiel #11
0
 void IBasicConsumer.HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
 {
     try
     {
         if (_ProcessMessages)
         {
             Interlocked.Increment(ref _MessageHandlingCount);
             MessageFormatter    messageFormatter = new MessageFormatter();
             ServiceEventMessage message          = messageFormatter.Deserialise(new MemoryStream(body));
             lock (_Queues)
             {
                 if (_Queues.ContainsKey(consumerTag))
                 {
                     MessageQueue queue = _Queues[consumerTag];
                     message.DeliveryID = Guid.NewGuid();
                     AckMessageInfo ackMessageInfo = new AckMessageInfo();
                     ackMessageInfo.DeliveryID     = message.DeliveryID;
                     ackMessageInfo.QueueName      = queue.QueueName;
                     ackMessageInfo.DeliveryTag    = deliveryTag;
                     ackMessageInfo.TotalExpected  = queue.Handlers.Count;
                     ackMessageInfo.ChannelHandler = this;
                     queue.AddAckMessageInfo(message.DeliveryID, ackMessageInfo);
                     message.Queue = queue.QueueName;
                     for (int index = 0; index < queue.Handlers.Count; index++)
                     {
                         try
                         {
                             MessageArrivedEventHandler handler = queue.Handlers[index];
                             handler.BeginInvoke(_ConnectionFactory.HostName, message, _Subscription.InvokeCallBack, new MessageArrivedState(handler, message, queue, ackMessageInfo));
                         }
                         catch (Exception ex)
                         {
                             _Subscription.NackMessage(message);
                             ApplicationEventLog.WriteEntry("Flow", ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
                         }
                     }
                     if (queue.Handlers.Count == 0)
                     {
                         Thread.Sleep(500);
                         _Model.BasicReject(deliveryTag, true);
                         Interlocked.Decrement(ref _MessageHandlingCount);
                         ApplicationEventLog.WriteEntry("Flow", string.Format("No handlers to process message {0}", consumerTag), System.Diagnostics.EventLogEntryType.Error);
                     }
                 }
                 else
                 {
                     Thread.Sleep(500);
                     _Model.BasicReject(deliveryTag, true);
                     Interlocked.Decrement(ref _MessageHandlingCount);
                     ApplicationEventLog.WriteEntry("Flow", string.Format("HandleBasicDeliver: Failed to locate queue {0}", consumerTag), System.Diagnostics.EventLogEntryType.Error);
                 }
             }
         }
     }
     catch (System.Runtime.Serialization.SerializationException)
     {
         string path = GetBadMessageDirectory();
         File.WriteAllBytes(Path.Combine(path, string.Concat(consumerTag, "_", Guid.NewGuid().ToString())), body);
         _Model.BasicReject(deliveryTag, false);
         Interlocked.Decrement(ref _MessageHandlingCount);
     }
     catch (Exception ex)
     {
         Thread.Sleep(500);
         try
         {
             if (_Model != null)
             {
                 _Model.BasicReject(deliveryTag, true);
             }
             Interlocked.Decrement(ref _MessageHandlingCount);
         }
         catch { }
         ApplicationEventLog.WriteEntry("Flow", ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
     }
 }
 public void Subscribe(bool machineSpecific, string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     CheckRabbitMQ();
     if (machineSpecific)
         queueName = string.Concat(Environment.MachineName, ".", queueName);
     if (temporary)
         queueName = string.Concat(queueName, ".", Guid.NewGuid().ToString());
     _DALRabbitMQ.Subscribe(queueName, durable, temporary, routingKey, handler);
     lock (_Subscriptions)
     {
         _Subscriptions.Add(new Subscription() { Durable = durable, Handler = handler, QueueName = queueName, RoutingKey = routingKey, Temporary = temporary });
     }
 }
 public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     Subscribe(false, queueName, durable, temporary, routingKey, handler);
 }
 public void Subscribe(string queueName, string routingKey, MessageArrivedEventHandler handler)
 {
     Subscribe(false, queueName, true, false, routingKey, handler);
 }
Beispiel #15
0
 public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
 {
     for (int index = 0; index < _ServerCount; index++)
     {
         _Subscriptions[index].Subscribe(queueName, durable, temporary, routingKey, handler);
     }
 }
Beispiel #16
0
 public AsynchronousSocketListener(MessageArrivedEventHandler handler)
 {
     MessageCompleted = handler;
 }
        public void Subscribe(string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler)
		{
			lock (_Queues)
			{
				if (_SubscriptionRequestThread == null)
				{
					_SubscriptionRequestThread = new Thread(new ThreadStart(ProcessSubscriptionRequests));
					if (_SubscriptionRequestThread.Name == null)
						_SubscriptionRequestThread.Name = "ProcessMQSubscriptionRequests";
					_SubscriptionRequestThread.IsBackground = true;
					_SubscriptionRequestThread.Start();
				}
				if (_Queues.ContainsKey(queueName))
				{
					MessageQueue queue = _Queues[queueName];
					queue.Handlers.Add(handler);
				}
				else
				{
					MessageQueue queue = new MessageQueue();
                    queue.Durable = durable;
					queue.QueueName = queueName;
					queue.RoutingKey = routingKey;
                    queue.Temporary = temporary;
					queue.ChannelName = queue.QueueName.Split('.')[0];
					queue.Handlers.Add(handler);
					_Queues.Add(queueName, queue);
					_SubscriptionToAdd.Enqueue(queue);
					_TriggerSubscriptionRequest.Set();
				}
			}
		}