Beispiel #1
0
        public Notification SendMessageToQueue(Notification notificationRequest)
        {
            MessageQueue messageQueue = null;

            if (notificationRequest == null && notificationRequest.EventList == null &&
                notificationRequest.EventList.Count.Equals(0))
            {
                return(notificationRequest);
            }

            messageQueue = _messageQueueService.Exists(queueName) ? new MessageQueue(queueName) :
                           _messageQueueService.Create(queueName, true);

            notificationRequest.EventList.ForEach(x => x.AttributesList.ForEach(
                                                      a => a.Add("ResponseToken", Guid.NewGuid().ToString())));

            try
            {
                messageQueue.Formatter = new BinaryMessageFormatter();
                // Since we're using a transactional queue, make a transaction.
                using (MessageQueueTransaction messageQueueTransaction = new MessageQueueTransaction())
                {
                    messageQueueTransaction.Begin();

                    // Send the message.
                    messageQueue.Send(notificationRequest, messageQueueTransaction);

                    messageQueueTransaction.Commit();
                }
            }
            catch (MessageQueueException ee)
            {
                notificationRequest.Status = Status.Failure;
                // logging
            }
            catch (Exception eee)
            {
                notificationRequest.Status = Status.Failure;
                //logging
            }
            finally
            {
                messageQueue.Close();
            }

            //Code to Send to MSMQ
            return(notificationRequest);
        }