示例#1
0
 public QueueListener(string inboundQueue, eMessageFetch fetchMethod, eMessageFormat messageFormat, Type customType)
 {
     if (inboundQueue.IndexOf("private$") < 0)
     {
         mobjInboundQueue = new MessageQueue(QUEUE_PREFIX + inboundQueue,QueueAccessMode.Receive);
     }
     else
     {
         mobjInboundQueue = new MessageQueue(inboundQueue, QueueAccessMode.Receive);
     }
     meFetchMethod = fetchMethod;
     meMessageFormat = messageFormat;
     mobjCustomType = customType;
 }
示例#2
0
        private IMessageFormatter SetQueueFormatterAndProperties(MessageQueue activeQueue, eMessageFormat messageFormat, Type customType)
        {
            IMessageFormatter objFormatter = null;
            MessagePropertyFilter objMessagePropertyFilter = new MessagePropertyFilter();

            // Message Formatter
            switch (messageFormat)
            {
                case eMessageFormat.XMLSerialize:
                    if (customType == null)
                    {
                        objFormatter = new XmlMessageFormatter();
                    }
                    else
                    {
                        objFormatter = new XmlMessageFormatter(new Type[] { customType });
                    }

                    break;
                case eMessageFormat.ActiveXSerialize:
                    objFormatter = new ActiveXMessageFormatter();
                    break;
                case eMessageFormat.BinarySerialize:
                    objFormatter = new BinaryMessageFormatter();
                    break;
            }

            // Messages in Private Queue
            // Ensure these properties are received (CorrelationID defaults to False)
            objMessagePropertyFilter.SetDefaults();
            objMessagePropertyFilter.CorrelationId = true;
            objMessagePropertyFilter.AppSpecific = true;
            objMessagePropertyFilter.ArrivedTime = true;
            activeQueue.MessageReadPropertyFilter = objMessagePropertyFilter;

            // Message Formatter
            activeQueue.Formatter = objFormatter;

            return objFormatter;
        }
示例#3
0
        public Message[] PeekMessages(MessageQueue activeQueue, bool blnDynamicConnection, eMessageFormat messageFormat, System.Type customType)
        {
            Message objMessage;
            Message[] arrCurrentMessages = new Message[0];
            Message[] arrCopyOfMessages = null;
            MessagePropertyFilter objMessagePropertyFilter = new MessagePropertyFilter();
            int intArrayIndex;

            // Message Formatter
            SetQueueFormatterAndProperties(activeQueue, messageFormat, customType);

            // Dynamic Connection whilst gathering messages
            if (blnDynamicConnection == true)
            {
                IEnumerator objMessageEnumerator = activeQueue.GetMessageEnumerator2();
                intArrayIndex = 0;
                while (objMessageEnumerator.MoveNext())
                {
                    objMessage = (Message)objMessageEnumerator.Current;
                    if (intArrayIndex > 0)
                    {
                        arrCopyOfMessages = new Message[intArrayIndex];
                        arrCurrentMessages.CopyTo(arrCopyOfMessages, 0);
                        arrCurrentMessages = arrCopyOfMessages;
                    }
                    arrCurrentMessages[intArrayIndex] = objMessage;
                    intArrayIndex += 1;
                }
            }
            else // Snapshot of messages currently in Queue
            {
                arrCurrentMessages = null;
                try
                {
                    arrCurrentMessages = activeQueue.GetAllMessages();
                }
                catch (System.Messaging.MessageQueueException excM)
                {
                    throw excM;
                }
            }

            return arrCurrentMessages;

        }