private static void SendMessageToQueue(string quepath, DocuwareMigrationDataPointer dataPointer) { //Initisalize the Message Queue DefaultPropertiesToSend dpts = new DefaultPropertiesToSend(); dpts.Label = "Docuware 5.1b, Data Queued for Import into OpenKM Community 6.3.1"; dpts.Recoverable = true; dpts.UseJournalQueue = true; dpts.AttachSenderId = true; MessageQueue msgq = null; if (!MessageQueue.Exists(quepath)) { msgq = MessageQueue.Create(quepath); msgq.SetPermissions("Everyone", MessageQueueAccessRights.FullControl); } MessageQueue pQueue = new MessageQueue(quepath); //pQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(DocuwareMigrationDataPointer) }); BinaryMessageFormatter formatter = new BinaryMessageFormatter(); System.Messaging.Message message = new System.Messaging.Message(dataPointer, formatter); message.Recoverable = true; pQueue.DefaultPropertiesToSend = dpts; //Send the message pQueue.Send(message); //REMOVE LATER //Receiving Message //Message Mymessage = pQueue.Receive(); //Mymessage.Formatter = new BinaryMessageFormatter(); //DocuwareMigrationDataPointer docuwareMigrationDataPointerReceiver = (DocuwareMigrationDataPointer) Mymessage.Body; }
public void SendToQueue(string queueName, bool sendToError) { Logger.InfoFormat("Отправка в [{0}]: [{1}]", queueName, ToString()); if (string.IsNullOrEmpty(Title)) { var stack = new System.Diagnostics.StackTrace(); Logger.ErrorFormat("Для сообщения не указан обязательный параметр Title: {0}", stack); throw new ArgumentException("Для сообщения не указан обязательный параметр Title"); } if (!sendToError) { SentCount++; } var fullQueueName = MessageQueues.FormatQueueName(HostName.MessageQueueHostName, queueName); MessageQueue queue; try { queue = new MessageQueue(fullQueueName); } catch (Exception ex) { Logger.ErrorFormat("Ошибка создания экземпляра очереди [{0}]: {1}", fullQueueName, ex); throw; } using (queue) { var msgProperties = new DefaultPropertiesToSend { Priority = QueueMessagePriority, Label = Title, Recoverable = true }; queue.Formatter = new BinaryMessageFormatter(); queue.DefaultPropertiesToSend = msgProperties; TimeSent = DateTime.Now; try { queue.Send(this); Logger.Info("Сообщение отправлено в очередь"); } catch (Exception ex) { Logger.ErrorFormat("Ошибка доставки сообщения [{0}] в [{1}]: {2}", Title, fullQueueName, ex); throw; } queue.Close(); } }