public void Start() { if (!enabled) { return; } if (Settings.AuditQueue == Address.Undefined) { Logger.Info("No Audit queue has been configured. No audit import will be performed. To enable imports add the ServiceBus/AuditQueue appsetting and restart ServiceControl"); return; } performanceCounters.Initialize(); queuePeeker = new MessageQueue(MsmqUtilities.GetFullPath(Settings.AuditQueue), QueueAccessMode.Peek); queuePeeker.MessageReadPropertyFilter.ClearAll(); queuePeeker.PeekCompleted += QueueOnPeekCompleted; enrichers = builder.BuildAll<IEnrichImportedMessages>().ToList(); Logger.InfoFormat("MSMQ Audit import is now started, feeding audit messages from: {0}", Settings.AuditQueue); countDownEvent.Idle += OnIdle; Logger.Debug("Ready to BeginPeek"); queuePeeker.BeginPeek(); }
public MsmqTransport() { _messageQueue = new MessageQueue(".\\private$\\TestQueue"); _messageQueue.PeekCompleted += OnMessagePeeked; _messageQueue.BeginPeek(); }
static void Main(string[] args) { _orderQueue = new MessageQueue(ORDER_QUEUE_PATH, QueueAccessMode.Receive); _orderQueue.PeekCompleted += _orderQueue_PeekCompleted; _orderQueue.BeginPeek(); Console.ReadLine(); }
protected override void OnStart(string[] args) { flights.getFlights(); hotels.GetHotelReservations(); MessageQueue queue = new MessageQueue(Reservation.QUEUE_PATH); queue.PeekCompleted += new PeekCompletedEventHandler(readAndPeek); queue.BeginPeek(); }
public void StartRead() { if (!MessageQueue.Exists(_queueName)) throw new Exception(); _queue = new MessageQueue(_queueName) {Formatter = new XmlMessageFormatter(new Type[] {typeof (string)})}; _queue.PeekCompleted += new PeekCompletedEventHandler(QueuePeekCompleted); _queue.BeginPeek(); }
public void OnStart(string[] args) { _stopRequested = false; _stopReady = true; _txQueue = new MessageQueue(QueueAddress, true); _txQueue.Formatter = new XmlMessageFormatter(new[] { typeof(BasicMessage) }); _txQueue.PeekCompleted += TxQueueOnPeekCompleted; Thread.Sleep(2000); // so I can see WPF bindings _txQueue.BeginPeek(); }
/// <inheritdoc /> public IAsyncResult BeginPeek(System.Messaging.MessageQueue messageQueue, TimeSpan timeout) { try { return(messageQueue.BeginPeek(timeout, MessageQueueTransactionType.Automatic)); } catch (Exception exception) { _logger.Debug(exception, "Error Peeking Head of Message Queues"); throw new MessageQueuePeekException("Begin", messageQueue, timeout, exception); } }
public void Initialize(EndpointAddress inputAddress, EndpointAddress errorAddress) { inputQueue = MsmqUtilities.GetQueue(inputAddress) ?? MsmqUtilities.CreateQueue(inputAddress); if (!MsmqUtilities.QueueExists(errorAddress)) { MsmqUtilities.CreateQueue(errorAddress); } inputQueue.MessageReadPropertyFilter = new MessagePropertyFilter { Body = true, Recoverable = true, Id = true, CorrelationId = true, Extension = true, AppSpecific = true, }; inputQueue.ReceiveCompleted += OnReceiveCompleted; inputQueue.PeekCompleted += OnPeekCompleted; inputQueue.BeginPeek(); }
public MessageInfo PeekAllMessage(StructuredQueue oQueueTemp, int myID, int MaxQuery) { //Message messages = null; MessageInfo MyInfo = new MessageInfo(); try { MessageQueue MessageInQueue = new System.Messaging.MessageQueue(oQueueTemp.sPath, QueueAccessMode.SendAndReceive); System.Messaging.Cursor cursor = MessageInQueue.CreateCursor(); Message m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current); Application.DoEvents(); ArrayList MyMessage = new ArrayList(); MessageInQueue.MessageReadPropertyFilter.Id = true; MessageInQueue.MessageReadPropertyFilter.Priority = true; MessageInQueue.MessageReadPropertyFilter.SentTime = true; MessageInQueue.MessageReadPropertyFilter.MessageType = true; MessageInQueue.MessageReadPropertyFilter.Label = true; MessageInQueue.MessageReadPropertyFilter.Body = true; MessageInQueue.BeginPeek(new TimeSpan(0, 0, 10, 0)); //MessageEnumerator msgQenum = MessageInQueue.GetMessageEnumerator2(); int index = 0; // MyInfo.ID = MessageInQueue.GetAllMessages().Length; if (m != null) { while ((m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current)) != null) //while (msgQenum.MoveNext()) { Application.DoEvents(); if (!(index > MaxQuery)) { // messages = msgQenum.Current; QueueInfos QueueInfo = new QueueInfos(); //QueueInfo.ID = messages.Id; //QueueInfo.SentTime = messages.SentTime.ToString(); //QueueInfo.Body = ReadMessageStream(messages.BodyStream); //QueueInfo.Label = messages.Label; //QueueInfo.Priority = messages.Priority.ToString(); //QueueInfo.MessageID = index.ToString(); //QueueInfo.Transact = oQueueTemp.bTransactional; //QueueInfo.Queue = oQueueTemp.sQueueName; QueueInfo.ID = m.Id; QueueInfo.SentTime = m.SentTime.ToString(); QueueInfo.Body = ReadMessageStream(m.BodyStream); QueueInfo.Label = m.Label; QueueInfo.Priority = m.Priority.ToString(); QueueInfo.MessageID = index.ToString(); QueueInfo.Transact = oQueueTemp.bTransactional; QueueInfo.Queue = oQueueTemp.sQueueName; MyMessage.Add(QueueInfo); } index++; PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Next); } } MyInfo.ID = index; MyInfo.Message = MyMessage; } catch {} return MyInfo; }
/// <summary> /// Starts to listen to a remote Transactional Queue and process Jobs /// This is not tested yet /// </summary> private void RunRemoteTransactionalFramework() { MessageQueue workflowQueue = new MessageQueue(ProcessorQueue.MessageQueue); ((XmlMessageFormatter)workflowQueue.Formatter).TargetTypes = new System.Type[] { Type.GetType(Utils.MESSAGE_BASE_TYPE + "." + processorJob.MessageClass) }; workflowQueue.MessageReadPropertyFilter.Priority = true; workflowQueue.PeekCompleted += new PeekCompletedEventHandler(workflowQueue_PeekCompleted); pool.WaitOne(); workflowQueue.BeginPeek(); while (!StopProcess) { Thread.Sleep(TimeSpan.FromSeconds(10)); } }
public void Init() { // open Listener queue m_InQueue = new MessageQueue(ListenerPath); m_InQueue.Formatter = new BinaryMessageFormatter(); m_InQueue.MessageReadPropertyFilter.AcknowledgeType = true; m_InQueue.MessageReadPropertyFilter.TimeToBeReceived = true; m_InQueue.MessageReadPropertyFilter.SourceMachine = true; m_InQueue.MessageReadPropertyFilter.SentTime = true; m_InQueue.MessageReadPropertyFilter.ResponseQueue = true; m_InQueue.PeekCompleted += new PeekCompletedEventHandler(Manager); m_Listening = true; m_InQueue.BeginPeek(); // both queue have to be transactional for retry mechanism if(m_InQueue.Transactional) { // retry queue path m_RetryQueuePath = ListenerPath + "_retry"; m_RetryQueue = new MessageQueue(m_RetryQueuePath); if(m_RetryQueue.Transactional) { m_RetryQueue.Formatter = new BinaryMessageFormatter(); m_RetryQueue.MessageReadPropertyFilter.ArrivedTime = true; m_RetryQueue.PeekCompleted += new PeekCompletedEventHandler(RetryManager); m_RetryListening = true; m_RetryQueue.BeginPeek(); } else { m_RetryQueue.Close(); m_RetryQueue = null; } } }
public static Task <MSMQ.Message> PeekAsync(this MSMQ.MessageQueue queue, TimeSpan timeout) { queue.MessageReadPropertyFilter = Filters.Peek; // just peek minimal details return(Task.Factory.FromAsync(queue.BeginPeek(timeout, queue), EndPeek)); }
public void Start() { // Any messages that fail conversion to a transportmessage is sent to the particular.servicecontrol.errors queue using low level Api // The actual queue name is based on service name to support mulitple instances on same host (particular.servicecontrol.errors is the default) var serviceControlErrorQueueAddress = Address.Parse(string.Format("{0}.errors", Settings.ServiceName)); serviceControlErrorQueue = new MessageQueue(MsmqUtilities.GetFullPath(serviceControlErrorQueueAddress), false, true, QueueAccessMode.Send); if (!enabled) { return; } if (Settings.AuditQueue == Address.Undefined) { Logger.Info("No Audit queue has been configured. No audit import will be performed. To enable imports add the ServiceBus/AuditQueue appsetting and restart ServiceControl"); return; } if (TerminateIfForwardingIsEnabledButQueueNotWritable()) { return; } performanceCounters.Initialize(); queuePeeker = new MessageQueue(MsmqUtilities.GetFullPath(Settings.AuditQueue), QueueAccessMode.Peek); queuePeeker.MessageReadPropertyFilter.ClearAll(); queuePeeker.PeekCompleted += QueueOnPeekCompleted; enrichers = builder.BuildAll<IEnrichImportedMessages>().ToList(); Logger.InfoFormat("MSMQ Audit import is now started, feeding audit messages from: {0}", Settings.AuditQueue); countDownEvent.Idle += OnIdle; Logger.Debug("Ready to BeginPeek"); queuePeeker.BeginPeek(); }
public void Start() { if (haveStarted) return; logger.DebugFormat("Starting msmq transport on: {0}", Endpoint); queue = InitalizeQueue(endpoint); if(subQueueInitializer != null) { subQueueInitializer.InitializeSubQueues(Endpoint,queue.Transactional); } foreach (var messageAction in messageActions) { messageAction.Init(this); } for (var t = 0; t < threadCount; t++) { var waitHandle = new ManualResetEvent(true); waitHandles[t] = waitHandle; try { queue.BeginPeek(TimeOutForPeek, new QueueState { Queue = queue, WaitHandle = waitHandle }, OnPeekMessage); waitHandle.Reset(); } catch (Exception e) { throw new TransportException("Unable to start reading from queue: " + endpoint, e); } } haveStarted = true; }
/// <summary> /// 异步接收事务消息队列消息 /// 异步接收BeginReceive()方法无MessageQueueTransaction重载(微软类库的Bug?) /// 这里变通一下:先异步BeginPeek(),然后带事务异步接收Receive(MessageQueueTransaction) /// </summary> private void AsyncReceiveWithTransactional() { var messageQueue = new MessageQueue(_transactionalQueuePath) { Formatter = new XmlMessageFormatter(new Type[] { typeof(MessageObj) }) }; messageQueue.PeekCompleted += new PeekCompletedEventHandler(OnPeekCompleted); //lblBeginTime.Text = DateTime.Now.ToString(); using (var messageEnumerator = messageQueue.GetMessageEnumerator2()) { while (messageEnumerator.MoveNext()) { try { messageQueue.BeginPeek(); } catch (Exception ex) { Debug.WriteLine("Exception:ReceiveMessage Exception:" + ex); } } } //lblEndTime.Text = DateTime.Now.ToString(); MessageBox.Show("Receive Done!"); }
public MessageInfo PeekAllMessage(StructuredQueue oQueueTemp, int myID, int MaxQuery) { //Message messages = null; MessageInfo MyInfo = new MessageInfo(); try { MessageQueue MessageInQueue = new System.Messaging.MessageQueue(oQueueTemp.sPath, QueueAccessMode.SendAndReceive); System.Messaging.Cursor cursor = MessageInQueue.CreateCursor(); Message m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current); Application.DoEvents(); ArrayList MyMessage = new ArrayList(); MessageInQueue.MessageReadPropertyFilter.Id = true; MessageInQueue.MessageReadPropertyFilter.Priority = true; MessageInQueue.MessageReadPropertyFilter.SentTime = true; MessageInQueue.MessageReadPropertyFilter.MessageType = true; MessageInQueue.MessageReadPropertyFilter.Label = true; MessageInQueue.MessageReadPropertyFilter.Body = true; MessageInQueue.BeginPeek(new TimeSpan(0, 0, 10, 0)); //MessageEnumerator msgQenum = MessageInQueue.GetMessageEnumerator2(); int index = 0; // MyInfo.ID = MessageInQueue.GetAllMessages().Length; if (m != null) { while ((m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current)) != null) //while (msgQenum.MoveNext()) { Application.DoEvents(); if (!(index > MaxQuery)) { // messages = msgQenum.Current; QueueInfos QueueInfo = new QueueInfos(); //QueueInfo.ID = messages.Id; //QueueInfo.SentTime = messages.SentTime.ToString(); //QueueInfo.Body = ReadMessageStream(messages.BodyStream); //QueueInfo.Label = messages.Label; //QueueInfo.Priority = messages.Priority.ToString(); //QueueInfo.MessageID = index.ToString(); //QueueInfo.Transact = oQueueTemp.bTransactional; //QueueInfo.Queue = oQueueTemp.sQueueName; QueueInfo.ID = m.Id; QueueInfo.SentTime = m.SentTime.ToString(); QueueInfo.Body = ReadMessageStream(m.BodyStream); QueueInfo.Label = m.Label; QueueInfo.Priority = m.Priority.ToString(); QueueInfo.MessageID = index.ToString(); QueueInfo.Transact = oQueueTemp.bTransactional; QueueInfo.Queue = oQueueTemp.sQueueName; MyMessage.Add(QueueInfo); } index++; PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Next); } } MyInfo.ID = index; MyInfo.Message = MyMessage; } catch {} return(MyInfo); }