void ISubscriptionStorage.Init() { var path = MsmqUtilities.GetFullPath(Queue); q = new MessageQueue(path); bool transactional; try { transactional = q.Transactional; } catch (Exception ex) { throw new ArgumentException(string.Format("There is a problem with the subscription storage queue {0}. See enclosed exception for details.", Queue), ex); } if (!transactional && TransactionsEnabled) throw new ArgumentException("Queue must be transactional (" + Queue + ")."); var messageReadPropertyFilter = new MessagePropertyFilter { Id = true, Body = true, Label = true }; q.Formatter = new XmlMessageFormatter(new[] { typeof(string) }); q.MessageReadPropertyFilter = messageReadPropertyFilter; foreach (var m in q.GetAllMessages()) { var subscriber = Address.Parse(m.Label); var messageTypeString = m.Body as string; var messageType = new MessageType(messageTypeString); //this will parse both 2.6 and 3.0 type strings entries.Add(new Entry { MessageType = messageType, Subscriber = subscriber }); AddToLookup(subscriber, messageType, m.Id); } }
public MsmqReceiver() { if (!Address.Local.Machine.Equals(RuntimeEnvironment.MachineName, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(String.Format("Input queue [{0}] must be on the same machine as this process [{1}].", Address.Local, RuntimeEnvironment.MachineName)); } queue = new MessageQueue(MsmqUtilities.GetFullPath(Address.Local), false, true, QueueAccessMode.Receive); var messageReadPropertyFilter = new MessagePropertyFilter { Body = true, TimeToBeReceived = true, Recoverable = true, Id = true, ResponseQueue = true, CorrelationId = true, Extension = true, AppSpecific = true }; queue.MessageReadPropertyFilter = messageReadPropertyFilter; if (PurgeOnStartup) { queue.Purge(); } }
public void Init() { lock (lockObj) { if (storageQueue != null) { return; } var storageQueueAddress = configure.LocalAddress.SubScope("distributor.storage"); var path = MsmqUtilities.GetFullPath(storageQueueAddress); var messageReadPropertyFilter = new MessagePropertyFilter { Id = true, Label = true, ResponseQueue = true, }; storageQueue = new MessageQueue(path, false, true, QueueAccessMode.SendAndReceive) { MessageReadPropertyFilter = messageReadPropertyFilter }; if ((!storageQueue.Transactional) && (configure.Settings.Get<bool>("Transactions.Enabled"))) { throw new Exception(string.Format("Queue [{0}] must be transactional.", path)); } } }
public static void ReturnMessageToSourceQueue(string errorQueueMachine, string errorQueueName, string msmqMessageId) { string path = string.Format(@"{0}\private$\{1}", errorQueueMachine, errorQueueName); MessageQueue errorQueue = new MessageQueue(path); { MessagePropertyFilter messageReadPropertyFilter = new MessagePropertyFilter { Body = true, TimeToBeReceived = true, Recoverable = true, Id = true, ResponseQueue = true, CorrelationId = true, Extension = true, AppSpecific = true, LookupId = true, }; errorQueue.MessageReadPropertyFilter = messageReadPropertyFilter; using (TransactionScope scope = new TransactionScope()) { MessageQueueTransactionType transactionType = MessageQueueTransactionType.Automatic; Message message = errorQueue.ReceiveById(msmqMessageId, TimeSpan.FromSeconds(5), transactionType); string fullPath = ReadFailedQueueHeader(message); using (MessageQueue failedQueue = new MessageQueue(fullPath)) { failedQueue.Send(message, transactionType); } scope.Complete(); } } }
private static MessageQueue InitializeQueue(MessageQueue q) { bool transactional; try { transactional = q.Transactional; } catch (Exception ex) { throw new InvalidOperationException( string.Format("There is a problem with the input queue given: {0}. See the enclosed exception for details.", q.Path), ex); } if (!transactional) { throw new ArgumentException("Queue must be transactional (" + q.Path + ")."); } var mpf = new MessagePropertyFilter(); mpf.SetAll(); q.MessageReadPropertyFilter = mpf; return q; }
void IMessageTransport.Init(Address address) { if (address == null) { throw new ArgumentNullException("address"); } var machine = address.Machine; if (machine.ToLower() != Environment.MachineName.ToLower()) { throw new InvalidOperationException( string.Format("Input queue [{0}] must be on the same machine as this process [{1}].", address, Environment.MachineName.ToLower())); } var fullPath = MsmqUtilities.GetFullPathWithoutPrefix(address); if (MessageQueue.Exists(fullPath)) { _messageQueue = new MessageQueue(fullPath); } else { _messageQueue = MessageQueue.Create(fullPath); } var mpf = new MessagePropertyFilter(); mpf.SetAll(); _messageQueue.MessageReadPropertyFilter = mpf; if (PurgeOnStartup) { _messageQueue.Purge(); } }
public Message() { this.properties = new MessagePropertyVariants(); this.receiveCreated = false; this.filter = new MessagePropertyFilter(); this.properties.SetUI1Vector(2, new byte[20]); this.filter.Id = true; }
public static MessageQueue GetOrCreateMessageQueue(string name) { MsmqUtilities.CreateQueueIfNecessary(name); var q = new MessageQueue(MsmqUtilities.GetFullPath(name)); var filter = new MessagePropertyFilter(); filter.SetAll(); q.MessageReadPropertyFilter = filter; return q; }
public Consumer(string channelName) { // Attach to a message queue identified in channelName and set the formatter channel = new MessageQueue(channelName) {Formatter = new XmlMessageFormatter(new[] {typeof(string)})}; // We want to trace message headers such as correlation id, so we need to tell MSMQ to retrieve those by setting the property filter MessagePropertyFilter filter = new MessagePropertyFilter(); filter.SetAll(); channel.MessageReadPropertyFilter = filter; }
/// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Messaging.Message'/> class with an empty body. /// </para> /// </devdoc> public Message() { properties = new MessagePropertyVariants(); receiveCreated = false; this.filter = new MessagePropertyFilter(); //Always add Id properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_MSGID, new byte[MessageIdSize]); this.filter.Id = true; }
static Filters() { // setup the filter used for peeking Peek = new MSMQ.MessagePropertyFilter(); Peek.ClearAll(); Peek.Label = true; // we read the body too Read = new MSMQ.MessagePropertyFilter { Body = true }; }
/// <summary> /// Initializes the <see cref="IDequeueMessages" />. /// </summary> /// <param name="address">The address to listen on.</param> /// <param name="settings">The <see cref="TransactionSettings" /> to be used by <see cref="IDequeueMessages" />.</param> /// <param name="tryProcessMessage">Called when a message has been dequeued and is ready for processing.</param> /// <param name="endProcessMessage"> /// Needs to be called by <see cref="IDequeueMessages" /> after the message has been /// processed regardless if the outcome was successful or not. /// </param> public void Init(Address address, TransactionSettings settings, Func<TransportMessage, bool> tryProcessMessage, Action<TransportMessage, Exception> endProcessMessage) { this.tryProcessMessage = tryProcessMessage; this.endProcessMessage = endProcessMessage; transactionSettings = settings; if (address == null) { throw new ArgumentException("Input queue must be specified"); } if (!address.Machine.Equals(RuntimeEnvironment.MachineName, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException( string.Format("Input queue [{0}] must be on the same machine as this process [{1}].", address, RuntimeEnvironment.MachineName)); } transactionOptions = new TransactionOptions { IsolationLevel = transactionSettings.IsolationLevel, Timeout = transactionSettings.TransactionTimeout }; queue = new MessageQueue(MsmqUtilities.GetFullPath(address), false, true, QueueAccessMode.Receive); if (transactionSettings.IsTransactional && !QueueIsTransactional()) { throw new ArgumentException( "Queue must be transactional if you configure your endpoint to be transactional (" + address + ")."); } var messageReadPropertyFilter = new MessagePropertyFilter { Body = true, TimeToBeReceived = true, Recoverable = true, Id = true, ResponseQueue = true, CorrelationId = true, Extension = true, AppSpecific = true }; queue.MessageReadPropertyFilter = messageReadPropertyFilter; if (PurgeOnStartup) { queue.Purge(); } }
public static MessageQueue GetOrCreateMessageQueue(string name) { CheckedQueues.GetOrAdd(name, n => { MsmqUtilities.CreateQueueIfNecessary(name); return null; }); var q = new MessageQueue(MsmqUtilities.GetFullPath(name), false, true); var filter = new MessagePropertyFilter(); filter.SetAll(); q.MessageReadPropertyFilter = filter; return q; }
public TextBodyHandler() { MessageReadPropertyFilter = new MessagePropertyFilter(); MessageReadPropertyFilter.ClearAll(); MessageReadPropertyFilter.DestinationQueue = true; MessageReadPropertyFilter.Id = true; MessageReadPropertyFilter.Label = true; MessageReadPropertyFilter.Priority = true; MessageReadPropertyFilter.MessageType = true; MessageReadPropertyFilter.ArrivedTime = true; MessageReadPropertyFilter.SentTime = true; MessageReadPropertyFilter.Body = true; }
static void Main(string[] args) { _mq = new MessageQueue(@".\private$\RequestQFileProcess", QueueAccessMode.Receive); _mq.ReceiveCompleted += new ReceiveCompletedEventHandler(_mq_ReceiveCompleted); _mq.Formatter = new ActiveXMessageFormatter(); MessagePropertyFilter filter = new MessagePropertyFilter(); filter.Label = true; filter.Body = true; filter.AppSpecific = true; _mq.MessageReadPropertyFilter = filter; DoReceive(); Console.ReadLine(); _mq.Close(); }
public Consumer(string channelName) { // Attach to a message queue and set the formatter so we can read the messages channel = new MessageQueue(channelName) {Formatter = new XmlMessageFormatter(new[] {typeof(string)})}; // We want to trace message headers such as correlation id, so we need to tell MSMQ to retrieve those MessagePropertyFilter filter = new MessagePropertyFilter(); filter.SetAll(); channel.MessageReadPropertyFilter = filter; //we use a timer to poll the queue at a regular interval, of course this may need to be re-entrant but we have no state to worry about timer = new Timer(ConfigurationSettings.PollingInterval) {AutoReset = true}; // on the Timer's Elapsed event we want to consume messages, so set the callback to our Consume method timer.Elapsed += timer_Elapsed; }
public static void Main(string[] args) { mongoDBWriter = new MongoDBWriter(); logQueue = new MessageQueue(@".\private$\loggingMongoDBQueue", QueueAccessMode.Receive); logQueue.ReceiveCompleted += MessageQueueReceiveCompleted; //we just want to pass around json strings, so we don't care about the contract logQueue.Formatter = new XmlMessageFormatter(){TargetTypes = new []{typeof(string)}}; var filter = new MessagePropertyFilter {Label = true, Body = true, AppSpecific = true}; logQueue.MessageReadPropertyFilter = filter; DoReceive(); Console.WriteLine("Application running and processing queue. Press any key to quit."); Console.ReadLine(); logQueue.Close(); }
protected override void ProcessRecord() { var queueAddress = string.Format("FormatName:DIRECT=OS:{0}\\private$\\{1}", Environment.MachineName,QueueName); var queue = new MessageQueue(queueAddress); var messageReadPropertyFilter = new MessagePropertyFilter {Id = true, Extension = true, ArrivedTime = true}; queue.MessageReadPropertyFilter = messageReadPropertyFilter; var output = queue.GetAllMessages().Select(m => new { m.Id, Headers = ParseHeaders(m), m.ArrivedTime }); WriteObject(output, true); }
public static void Pick_From_NServiceBus_Msmq() { var address = Address.Parse("*****@*****.**"); address = Address.Parse("MessageMonitorAudit"); var path = NServiceBus.Utils.MsmqUtilities.GetFullPath(address); using (var queue = new MessageQueue(path, QueueAccessMode.PeekAndAdmin)) { var mpf = new MessagePropertyFilter(); mpf.SetAll(); queue.MessageReadPropertyFilter = mpf; var msg = queue.Peek(TimeSpan.FromMinutes(1)); var tm = NServiceBus.Utils.MsmqUtilities.Convert(msg); if(tm.Is_Failed_Message()) tm.To_NServiceBus_Failed_Message(); } }
public MsmqSubscriptionStorageQueue(MsmqAddress queueAddress, bool useTransactionalQueue) { transactionTypeToUseForSend = useTransactionalQueue ? MessageQueueTransactionType.Single : MessageQueueTransactionType.None; queue = new MessageQueue(queueAddress.FullPath); var messageReadPropertyFilter = new MessagePropertyFilter { Id = true, Body = true, Label = true, ArrivedTime = true }; queue.Formatter = new XmlMessageFormatter(new[] { typeof(string) }); queue.MessageReadPropertyFilter = messageReadPropertyFilter; }
public MsmqQueue(Uri uri, IMsmqConfiguration configuration) { Guard.AgainstNull(uri, "uri"); Guard.AgainstNull(configuration, "configuration"); _log = Log.For(this); _parser = new MsmqUriParser(uri); _timeout = _parser.Local ? TimeSpan.FromMilliseconds(configuration.LocalQueueTimeoutMilliseconds) : TimeSpan.FromMilliseconds(configuration.RemoteQueueTimeoutMilliseconds); Uri = _parser.Uri; _messagePropertyFilter = new MessagePropertyFilter(); _messagePropertyFilter.SetAll(); _dequeuePipelinePool = new ReusableObjectPool<MsmqGetMessagePipeline>(); }
public MsmqWorkerAvailabilityManager() { var storageQueueAddress = Address.Local.SubScope("distributor.storage"); var path = MsmqUtilities.GetFullPath(storageQueueAddress); var messageReadPropertyFilter = new MessagePropertyFilter { Id = true, Label = true, ResponseQueue = true, }; storageQueue = new MessageQueue(path, false, true, QueueAccessMode.SendAndReceive) { MessageReadPropertyFilter = messageReadPropertyFilter }; if ((!storageQueue.Transactional) && (SettingsHolder.Get<bool>("Transactions.Enabled"))) { throw new Exception(string.Format("Queue [{0}] must be transactional.", path)); } }
public void Instrument() { foreach (var serviceInfo in Services) { var address = new Address(serviceInfo.ErrorQueue, MachineName); var queue = new MessageQueue(MsmqUtilities.GetFullPath(address)); var filter = new MessagePropertyFilter(); filter.SetAll(); queue.MessageReadPropertyFilter = filter; var messages = queue.GetAllMessages(); foreach (var message in messages) { var transportMessage = MsmqUtilities.Convert(message); if (transportMessage.Headers.ContainsKey(Faults.FaultsHeaderKeys.FailedQ)) { var value = Address.Parse(transportMessage.Headers[Faults.FaultsHeaderKeys.FailedQ]); if (serviceInfo.Name.Equals(value.Queue, StringComparison.InvariantCultureIgnoreCase)) { var messageText = Encoding.UTF8.GetString(transportMessage.Body); using (var con = GetConnection()) { const string sql = "INSERT INTO Error (ErrorId, ServiceName, MachineName, Message, ErrorMessage, Stacktrace, MessageSentTimeUtc) VALUES(@errorId, @serviceName, @machineName, @message, @errorMessage, @stacktrace, @messageSentTimeUtc)"; var errorMessage = transportMessage.Headers["NServiceBus.ExceptionInfo.Message"]; var stackTrace = transportMessage.Headers["NServiceBus.ExceptionInfo.StackTrace"]; var messageSentTimeUtc = transportMessage.Headers["NServiceBus.TimeOfFailure"].ToUtcDateTime(); con.Execute(sql, new { ErrorId = Guid.NewGuid(), serviceName = serviceInfo.Name, MachineName, message = messageText, errorMessage, stackTrace, messageSentTimeUtc }); } } } } } }
/// <include file='doc\Message.uex' path='docs/doc[@for="Message.Message3"]/*' /> /// <internalonly/> internal Message(MessagePropertyFilter filter) { properties = new MessagePropertyVariants(); receiveCreated = true; this.filter = filter; if (filter.data1 != 0) { int data = filter.data1; if (0 != (data & MessagePropertyFilter.ACKNOWLEDGEMENT)) properties.SetUI2(NativeMethods.MESSAGE_PROPID_CLASS, (short)0); if (0 != (data & MessagePropertyFilter.ACKNOWLEDGE_TYPE)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_ACKNOWLEDGE, (byte)0); if (0 != (data & MessagePropertyFilter.ADMIN_QUEUE)) { properties.SetString(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE, new byte[DefaultQueueNameSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_ADMIN_QUEUE_LEN, DefaultQueueNameSize); } if (0 != (data & MessagePropertyFilter.BODY)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_BODY, new byte[filter.bodySize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_SIZE, filter.bodySize); properties.SetUI4(NativeMethods.MESSAGE_PROPID_BODY_TYPE, 0); } if (0 != (data & MessagePropertyFilter.LABEL)) { properties.SetString(NativeMethods.MESSAGE_PROPID_LABEL, new byte[filter.labelSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_LABEL_LEN, filter.labelSize); } if (0 != (data & MessagePropertyFilter.ID)) properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_MSGID, new byte[MessageIdSize]); if (0 != (data & MessagePropertyFilter.LOOKUP_ID)) properties.SetUI8(NativeMethods.MESSAGE_PROPID_LOOKUPID, (long)0); if (0 != (data & MessagePropertyFilter.USE_DEADLETTER_QUEUE)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)0); if (0 != (data & MessagePropertyFilter.RESPONSE_QUEUE)) { properties.SetString(NativeMethods.MESSAGE_PROPID_RESP_QUEUE, new byte[DefaultQueueNameSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_RESP_QUEUE_LEN, DefaultQueueNameSize); } //Acknowledgment and MessageType are overloaded in MQ. if ((0 == (data & MessagePropertyFilter.ACKNOWLEDGEMENT)) && (0 != (data & MessagePropertyFilter.MESSAGE_TYPE))) properties.SetUI2(NativeMethods.MESSAGE_PROPID_CLASS, (short)0); //Journaling and Deadletter are overloaded in MSMQ if ((0 == (data & MessagePropertyFilter.USE_DEADLETTER_QUEUE)) && (0 != (data & MessagePropertyFilter.USE_JOURNALING))) properties.SetUI1(NativeMethods.MESSAGE_PROPID_JOURNAL, (byte)0); } if (filter.data2 != 0) { int data = filter.data2; if (0 != (data & MessagePropertyFilter.APP_SPECIFIC)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_APPSPECIFIC, 0); if (0 != (data & MessagePropertyFilter.ARRIVED_TIME)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_ARRIVEDTIME, 0); if (0 != (data & MessagePropertyFilter.ATTACH_SENDER_ID)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_TYPE, 0); if (0 != (data & MessagePropertyFilter.AUTHENTICATED)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_AUTHENTICATED, (byte)0); if (0 != (data & MessagePropertyFilter.CONNECTOR_TYPE)) properties.SetGuid(NativeMethods.MESSAGE_PROPID_CONNECTOR_TYPE, new byte[GenericIdSize]); if (0 != (data & MessagePropertyFilter.CORRELATION_ID)) properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_CORRELATIONID, new byte[MessageIdSize]); if (0 != (data & MessagePropertyFilter.CRYPTOGRAPHIC_PROVIDER_NAME)) { properties.SetString(NativeMethods.MESSAGE_PROPID_PROV_NAME, new byte[DefaultCryptographicProviderNameSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_NAME_LEN, DefaultCryptographicProviderNameSize); } if (0 != (data & MessagePropertyFilter.CRYPTOGRAPHIC_PROVIDER_TYPE)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_PROV_TYPE, 0); if (0 != (data & MessagePropertyFilter.IS_RECOVERABLE)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_DELIVERY, (byte)0); if (0 != (data & MessagePropertyFilter.DESTINATION_QUEUE)) { properties.SetString(NativeMethods.MESSAGE_PROPID_DEST_QUEUE, new byte[DefaultQueueNameSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_DEST_QUEUE_LEN, DefaultQueueNameSize); } if (0 != (data & MessagePropertyFilter.DIGITAL_SIGNATURE)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SIGNATURE, new byte[DefaultDigitalSignatureSize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_SIGNATURE_LEN, DefaultDigitalSignatureSize); } if (0 != (data & MessagePropertyFilter.ENCRYPTION_ALGORITHM)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_ENCRYPTION_ALG, 0); if (0 != (data & MessagePropertyFilter.EXTENSION)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_EXTENSION, new byte[filter.extensionSize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_EXTENSION_LEN, filter.extensionSize); } if (0 != (data & MessagePropertyFilter.FOREIGN_ADMIN_QUEUE)) { properties.SetString(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE, new byte[DefaultQueueNameSize * 2]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_XACT_STATUS_QUEUE_LEN, DefaultQueueNameSize); } if (0 != (data & MessagePropertyFilter.HASH_ALGORITHM)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_HASH_ALG, 0); if (0 != (data & MessagePropertyFilter.IS_FIRST_IN_TRANSACTION)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_FIRST_IN_XACT, (byte)0); if (0 != (data & MessagePropertyFilter.IS_LAST_IN_TRANSACTION)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_LAST_IN_XACT, (byte)0); if (0 != (data & MessagePropertyFilter.PRIORITY)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_PRIORITY, (byte)0); if (0 != (data & MessagePropertyFilter.SENDER_CERTIFICATE)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDER_CERT, new byte[DefaultSenderCertificateSize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDER_CERT_LEN, DefaultSenderCertificateSize); } if (0 != (data & MessagePropertyFilter.SENDER_ID)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_SENDERID, new byte[DefaultSenderIdSize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENDERID_LEN, DefaultSenderIdSize); } if (0 != (data & MessagePropertyFilter.SENT_TIME)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_SENTTIME, 0); if (0 != (data & MessagePropertyFilter.SOURCE_MACHINE)) properties.SetGuid(NativeMethods.MESSAGE_PROPID_SRC_MACHINE_ID, new byte[GenericIdSize]); if (0 != (data & MessagePropertyFilter.SYMMETRIC_KEY)) { properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY, new byte[DefaultSymmetricKeySize]); properties.SetUI4(NativeMethods.MESSAGE_PROPID_DEST_SYMM_KEY_LEN, DefaultSymmetricKeySize); } if (0 != (data & MessagePropertyFilter.TIME_TO_BE_RECEIVED)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_BE_RECEIVED, 0); if (0 != (data & MessagePropertyFilter.TIME_TO_REACH_QUEUE)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_TIME_TO_REACH_QUEUE, 0); if (0 != (data & MessagePropertyFilter.TRANSACTION_ID)) properties.SetUI1Vector(NativeMethods.MESSAGE_PROPID_XACTID, new byte[MessageIdSize]); if (0 != (data & MessagePropertyFilter.USE_AUTHENTICATION)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_AUTH_LEVEL, 0); if (0 != (data & MessagePropertyFilter.USE_ENCRYPTION)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_PRIV_LEVEL, 0); if (0 != (data & MessagePropertyFilter.USE_TRACING)) properties.SetUI1(NativeMethods.MESSAGE_PROPID_TRACE, (byte)0); if (0 != (data & MessagePropertyFilter.VERSION)) properties.SetUI4(NativeMethods.MESSAGE_PROPID_VERSION, 0); } }
public int Transfer(string subject, string destination, string expression, bool caseInsensitive, bool removeAfter) { MessageQueueTransaction transaction = null; int ret = 0; Regex matcher = null; if (expression != null) matcher = new Regex("(" + expression + ")", RegexOptions.Compiled | (caseInsensitive ? RegexOptions.IgnoreCase : RegexOptions.None)); var messagePropertyFilter = new MessagePropertyFilter { ArrivedTime = true, Body = true, Id = true, Label = true }; var messageQueue = new MessageQueue(subject); if (!Exists(destination)) { throw new Exception("Can't write to non-existing queue " + destination + ". You can create it with qtouch."); } var destinationQueue = new MessageQueue(destination); if (!destinationQueue.CanWrite) { throw new Exception("Can't write to non-writable queue " + destination); } if (destinationQueue.Transactional) { transaction = new MessageQueueTransaction(); transaction.Begin(); } destinationQueue.Formatter = messageQueue.Formatter; messageQueue.MessageReadPropertyFilter = messagePropertyFilter; var messageEnumerator2 = messageQueue.GetMessageEnumerator2(); while (messageEnumerator2.MoveNext()) { if (messageEnumerator2.Current == null) continue; var message = messageEnumerator2.Current; if (matcher != null) { using (var streamReader = new StreamReader(message.BodyStream)) { string body = streamReader.ReadToEnd(); if (!matcher.IsMatch(body)) continue; Send(message, destinationQueue, transaction); } } else { Send(message, destinationQueue, transaction); } ret++; if (removeAfter) messageEnumerator2.RemoveCurrent(); } if (transaction!=null) transaction.Commit(); return ret; }
public IEnumerable<MessageDescriptor> Tail(string queue) { var messagePropertyFilter = new MessagePropertyFilter { ArrivedTime = true, Body = true, Id = true, Label = true }; var messageQueue = new MessageQueue(queue); messageQueue.MessageReadPropertyFilter = messagePropertyFilter; var messageEnumerator2 = messageQueue.GetMessageEnumerator2(); while(true) { //arbitrary, 1 day. while(messageEnumerator2.MoveNext(TimeSpan.FromDays(1))) { if(messageEnumerator2.Current == null) continue; yield return CreateMessageDescriptor(messageEnumerator2.Current); } } }
public IEnumerable<GrepResult> Grep(string subject, string expression, bool caseInsensitive) { Regex matcher = new Regex("(" + expression + ")", RegexOptions.Compiled | (caseInsensitive ? RegexOptions.IgnoreCase : RegexOptions.None)); var messagePropertyFilter = new MessagePropertyFilter { ArrivedTime = true, Body = true, Id = true, Label = true }; var messageQueue = new MessageQueue(subject); messageQueue.MessageReadPropertyFilter = messagePropertyFilter; var messageEnumerator2 = messageQueue.GetMessageEnumerator2(); while (messageEnumerator2.MoveNext()) { if (messageEnumerator2.Current == null) continue; var message = messageEnumerator2.Current; using (var streamReader = new StreamReader(message.BodyStream)) { string body = streamReader.ReadToEnd(); if (!matcher.IsMatch(body)) continue; yield return new GrepResult {Message = CreateMessageDescriptor(message), Text = matcher.HighlightMatch(body, "<{0}>")}; } } }
public int Count(string queue) { var messagePropertyFilter = new MessagePropertyFilter { AdministrationQueue = false, ArrivedTime = false, CorrelationId = false, Priority = false, ResponseQueue = false, SentTime = false, Body = false, Label = false, Id = false }; var messageQueue = new MessageQueue(queue); messageQueue.MessageReadPropertyFilter = messagePropertyFilter; return messageQueue.GetAllMessages().Length; }
public void Init(Address address, bool transactional) { useTransactions = transactional; if (address == null) throw new ArgumentException("Input queue must be specified"); var machine = address.Machine; if (machine.ToLower() != Environment.MachineName.ToLower()) throw new InvalidOperationException(string.Format("Input queue [{0}] must be on the same machine as this process [{1}].", address, Environment.MachineName.ToLower())); myQueue = new MessageQueue(MsmqUtilities.GetFullPath(address)); if (useTransactions && !QueueIsTransactional()) throw new ArgumentException("Queue must be transactional (" + address + ")."); var mpf = new MessagePropertyFilter(); mpf.SetAll(); myQueue.MessageReadPropertyFilter = mpf; if (PurgeOnStartup) myQueue.Purge(); }
private Message[] PeekMessages(MessageQueue activeQueue, bool blnDynamicConnection, MessageFormat eMessageFormat, System.Type CustomType) { Message objMessage; Message[] arrCurrentMessages = new Message[0]; Message[] arrCopyOfMessages = null; IMessageFormatter objFormatter = null ; MessagePropertyFilter objMessagePropertyFilter = new MessagePropertyFilter(); int intArrayIndex; // Message Formatter switch (eMessageFormat) { case MessageFormat.XMLSerialize: if (CustomType == null) { objFormatter = new XmlMessageFormatter(); } else { // objFormatter = new XmlMessageFormatter(new Type() [CustomType]); } break; case MessageFormat.ActiveXSerialize: objFormatter = new ActiveXMessageFormatter(); break; case MessageFormat.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; // Dynamic Connection whilst gathering messages if (blnDynamicConnection == true) { IEnumerator objMessageEnumerator = activeQueue.GetEnumerator(); 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; }
public IEnumerable<CatResult> Cat(string subject, bool withExtension) { var messagePropertyFilter = new MessagePropertyFilter { ArrivedTime = true, Body = true, Id = true, Label = true, Extension = withExtension }; var messageQueue = new MessageQueue(subject); messageQueue.MessageReadPropertyFilter = messagePropertyFilter; var messageEnumerator2 = messageQueue.GetMessageEnumerator2(); while (messageEnumerator2.MoveNext()) { if (messageEnumerator2.Current == null) continue; var message = messageEnumerator2.Current; using (var streamReader = new StreamReader(message.BodyStream)) { string body = streamReader.ReadToEnd(); yield return new CatResult { Message = CreateMessageDescriptor(message), Text = body, Extension = withExtension ? message.Extension : null }; } } }