protected virtual void Dispose(bool disposing) { if (disposing) { if (_messageQueue != null) { _messageQueue.Close(); } } }
public void DeleteMessage(ref GlobalVariables oVar, string FormatType, string MSMQServer, string QueueName, string MessageId,string MessageLabel) { string MQPath = FormatType + MSMQServer + "\\" + QueueName; try { MessageQueue oMQueue = new MessageQueue(MQPath); try { oMQueue.ReceiveById(MessageId); oVar.sStatusMessage = " Message succesfully deleted"; //MessageBox.Show(MessageLabel + " Message succesfully deleted", // "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); //MessageBox.Show(ex + "Queue Name is not valid or exist"); oVar.sStatusMessage = ex.Message; } oMQueue.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message Queuing Admin", MessageBoxButtons.OK, MessageBoxIcon.Information); oVar.sStatusMessage = ex.Message; } }
/// <summary> /// Start the listen to the queue for incoming messages and /// notifiy the handlers as new messges arrive /// </summary> private void StartQueueListener() { //create a separate connection to the message queue System.Messaging.MessageQueue listenermq = new System.Messaging.MessageQueue(formatName); ((XmlMessageFormatter)listenermq.Formatter).TargetTypeNames = (string[])(supportedTypes.ToArray(typeof(System.String))); System.Messaging.Message message = null; queueListenerStarted = true; try { //listen to the queue continusly through loop while (queueListenerStarted == true) { System.Threading.Thread.Sleep(sleepTime); if (handler.GetInvocationList().Length > 0) { //this is a call that will block the thread if no //message is in the queue. message = listenermq.Receive(); SAF.MessageQueue.Message safMessage = new SAF.MessageQueue.Message(); safMessage.Label = message.Label; safMessage.Content = message.Body; //fire the event handler(safMessage, queueName); } } } finally { //close the connetion listenermq.Close(); } }
public void SendMessageToQueue(string queueName, CallDisposition data) { var msMq = new MessageQueue(queueName); var myMessage = new System.Messaging.Message(); myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(CallDisposition) }); myMessage.Body = data; myMessage.Label = "MessageQueue"; myMessage.UseJournalQueue = true; myMessage.Recoverable = true; //message send acknowledgement. myMessage.AdministrationQueue = new MessageQueue(@".\Private$\MessageAcknowledgeQueue"); myMessage.AcknowledgeType = AcknowledgeTypes.PositiveReceive | AcknowledgeTypes.PositiveArrival; try { msMq.Send(myMessage); Console.WriteLine("Message sent successfully!"); } catch (MessageQueueException e) { Console.Write(e.ToString()); } catch (Exception e) { Console.Write(e.ToString()); } finally { msMq.Close(); } }
public bool addReservation(DemandeReservation reservation) { MessageQueue queue = new MessageQueue(FlyHotelConstant.ADRESSE_QUEUE); queue.Send(reservation); queue.Close(); return true; }
public void LogTwoMessagesToQueueAndBeAbleToReadBothOfThem() { string path = @"FormatName:DIRECT=OS:" + CommonUtil.MessageQueuePath; MsmqSinkData sinkParams = new MsmqSinkData(); sinkParams.QueuePath = path; MsmqSink sink = new MsmqSink(); sink.Initialize(new TestLogSinkConfigurationView(sinkParams)); CommonUtil.SendTestMessage(sink); using (MessageQueue mq = new MessageQueue(path)) { Message msg = mq.Receive(new TimeSpan(0, 0, 1)); mq.Close(); msg.Formatter = new XmlMessageFormatter(new string[] {"System.String,mscorlib"}); Assert.AreEqual(CommonUtil.FormattedMessage, msg.Body.ToString()); } CommonUtil.SendTestMessage(sink); using (MessageQueue mq = new MessageQueue(path)) { Message msg = mq.Receive(new TimeSpan(0, 0, 1)); mq.Close(); msg.Formatter = new XmlMessageFormatter(new string[] {"System.String,mscorlib"}); Assert.AreEqual(CommonUtil.FormattedMessage, msg.Body.ToString()); } }
static void Run() { MessageQueue queue = null; MessageQueueTransaction trans = null; try { queue = new MessageQueue(); queue.Path = Constants.QUEUE_PATH; queue.DefaultPropertiesToSend.Recoverable = true; trans = new MessageQueueTransaction(); trans.Begin(); MyOrder order = new MyOrder(); order.ID = DateTime.Now.Ticks.ToString(); order.Name = "Order_" + order.ID; Message msg = new Message(order); queue.Send(msg, trans); trans.Commit(); } catch (Exception ex) { trans.Abort(); } finally { queue.Close(); } Console.WriteLine("message sent.."); }
/// <summary> /// close the connection to the message queue /// </summary> public void Close() { if (mq != null) { mq.Close(); mq.Dispose(); } }
/// <summary> /// Disconnect from queue /// </summary> protected void DisconnectInternal() { MessageQueue?.Close(); MessageQueue?.Dispose(); MessageQueue = null; Logger.Debug("Disconnect from Message Queue {%Queue}", ToJson()); }
static void Example2() { Console.WriteLine("Example2"); MessageQueue queue = new MessageQueue(privateQueueName); queue.Send("Hello!"); queue.Close(); Console.WriteLine("End"); Console.WriteLine(); }
public static void ClearMessageQueue(string queue) { string mqName = CreateMessageQueueName(queue); if (!MessageQueue.Exists(mqName)) MessageQueue.Create(mqName, true); else { using (MessageQueue mq = new MessageQueue(mqName, false, false, QueueAccessMode.SendAndReceive)) { mq.Purge(); mq.Close(); } } }
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(); }
private void btnLire_Click(object sender, EventArgs e) { MessageQueue mqVols = new MessageQueue(@".\private$\cmdvols"); MessageQueue mqHotels = new MessageQueue(@".\private$\cmdhotels"); mqVols.Formatter = new XmlMessageFormatter(new Type[] { typeof(clsVolEntity) }); mqHotels.Formatter = new XmlMessageFormatter(new Type[] { typeof(clsHotelEntity) }); var messageVol = (clsVolEntity)mqVols.Peek().Body; var messageHotel = (clsHotelEntity)mqHotels.Peek().Body; clsVolEntity vol = new clsVolEntity(); vol.dateDepart = messageVol.dateDepart; vol.villeDepart = messageVol.villeDepart; vol.paysDepart = messageVol.paysDepart; vol.villeDestination = messageVol.villeDestination; vol.paysDestination = messageVol.paysDestination; vol.prixVol = messageVol.prixVol; vol.infoClient = messageVol.infoClient; clsHotelEntity hotel = new clsHotelEntity(); hotel.nomHotel = messageHotel.nomHotel; hotel.adresseHotel = messageHotel.adresseHotel; hotel.cpHotel = messageHotel.cpHotel; hotel.villeHotel = messageHotel.villeHotel; hotel.paysHotel = messageHotel.paysHotel; hotel.dateArrivee = messageHotel.dateArrivee; hotel.duree = messageHotel.duree; hotel.infoClient = messageHotel.infoClient; clsInfoClient client = vol.infoClient; // Enregistrement en mode transactionnel bool resEnregistrement = new TraitementCommandeLibrary.libTraitementCommande().ajouterCommande(hotel, vol, client); // Transaction OK if (resEnregistrement == true) { txtListe.AppendText("Enregistrement du vol " + vol.villeDepart + " - " + vol.villeDestination + " et l'hotel " + hotel.nomHotel); mqVols.Receive(); mqHotels.Receive(); } // Transaction KO else { txtListe.AppendText("Impossible d'enregsitrer le vol " + vol.villeDepart + " - " + vol.villeDestination + " et l'hotel " + hotel.nomHotel); } mqVols.Close(); mqHotels.Close(); }
public static string SendImpression3(int IDSubScheduleDetail) { try { MessageQueue MQ = new MessageQueue(server_msmq); MQ.Send(string.Format("IDSub:{0}:{1:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, DateTime.Now), string.Format("IDSub:{0}:{1:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, DateTime.Now)); MQ.Dispose(); MQ.Close(); return "done"; } catch(Exception ex) { return ex.Message; } }
public static bool SendClick(string IDSubScheduleDetail, string IDSubpage) { try { MessageQueue MQ = new MessageQueue(MQ_CLICK); MQ.Send(string.Format("IDSub:{0},{1}:{2:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, IDSubpage, DateTime.Now), string.Format("IDSub:{0},{1}:{2:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, IDSubpage, DateTime.Now)); MQ.Dispose(); MQ.Close(); return true; } catch { return false; } }
public static bool SendImpression(int IDSubScheduleDetail) { try { MessageQueue MQ = new MessageQueue(server_msmq); MQ.Send(string.Format("IDSub:{0}:{1:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, DateTime.Now), string.Format("IDSub:{0}:{1:dd/MM/yyyy HH-mm}", IDSubScheduleDetail, DateTime.Now)); MQ.Dispose(); MQ.Close(); return true; } catch { return false; } }
public void EnviarMensaje(object mensaje, string id, string nombreColaRequest, string nombreColaResponse) { MessageQueue colaRequest = new MessageQueue(PRIVATE_QUEQUE + nombreColaRequest); EstablecerFormateador(colaRequest); Message Msg = new Message(mensaje) { ResponseQueue = new MessageQueue(PRIVATE_QUEQUE + nombreColaResponse) }; EstablecerFormateador(Msg.ResponseQueue); Msg.Label = id; colaRequest.Send(Msg); colaRequest.Close(); }
public static void ClearQueue(string sQueue) { MessageQueue oQueue; try { if (!MessageQueue.Exists(sQueue)) { MessageQueue.Create(sQueue); } oQueue = new MessageQueue(sQueue); oQueue.Purge(); oQueue.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } }
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(); }
private void button1_Click(object sender, EventArgs e) { MessageQueue msgQ = new MessageQueue(_msgQRec); System.Messaging.Message m = new System.Messaging.Message(); m.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) }); try { //When we pull the message off from the queue it will be in the form of a //byte array m = msgQ.Receive(); byte[] data = new byte[1024]; m.BodyStream.Read(data, 0, 1024); string strMessage = ASCIIEncoding.ASCII.GetString(data); //load message into XmlDocument XmlDocument xml = new XmlDocument(); xml.LoadXml(strMessage); //Deserialize Xml Document into a typed C# object var ser = new XmlSerializer(typeof(WorkOrderRequests)); var wo = (WorkOrderRequests)ser.Deserialize(new StringReader(xml.OuterXml)); //Populate our GUI txtFunctionalLocation.Text = wo.WorkOrderRequest[0].FunctionalLocation; txtMachineID.Text = wo.WorkOrderRequest[0].MachinedID; txtMaintenanceType.Text = wo.WorkOrderRequest[0].MaintenanceType; txtPlant.Text = wo.WorkOrderRequest[0].Plant; txtRequestedDate.Text = wo.WorkOrderRequest[0].RequestDate.ToString(); txtWorkOrderID.Text = wo.WorkOrderRequest[0].WorkOrderID; btnCompleteWorkOrder.Visible = true; msgQ.Close(); msgQ.Dispose(); } catch (Exception ex) { MessageBox.Show(String.Format("An exception has occurred {0}", ex.ToString())); } }
public void Send(MessageQueue messageQueue, string message, MessageQueueTransaction transaction) { try { var msg = new Message { UseAuthentication = false, Recoverable = true, Body = message }; messageQueue.Send(msg, transaction); } finally { messageQueue.Close(); } }
public void SerializeMessageToMSMQ() { LogEntry logEntry = CommonUtil.GetDefaultLogEntry(); msmq.SendLog(logEntry); string path = @"FormatName:DIRECT=OS:" + CommonUtil.MessageQueuePath; MessageQueue mq = new MessageQueue(path); Message msg = mq.Receive(new TimeSpan(0, 0, 1)); msg.Formatter = new XmlMessageFormatter(new string[] {"System.String,mscorlib"}); mq.Close(); mq = null; string actual = msg.Body.ToString(); Assert.IsTrue(actual.IndexOf(CommonUtil.MsgCategory) > 0); Assert.IsTrue(actual.IndexOf(logEntry.Message) > 0); }
private void btnRead_Click(object sender, EventArgs e) { MessageQueue MyMQ = new MessageQueue(@".\private$\BankENSEIRB"); MyMQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(TransfertInfo) }); var message = (TransfertInfo)MyMQ.Peek().Body; bool ResT = Transfert(message.BO, message.BD, message.CC, message.CD, message.Montant); if (ResT == true) { MyMQ.Receive(); MyMQ.r } else { } MyMQ.Close(); }
public static Message[] GetAllMessages(string queue) { string mqName = CreateMessageQueueName(queue); if (!MessageQueue.Exists(mqName)) { MessageQueue.Create(mqName, true); return null; } else { Message[] ret = null; using (MessageQueue mq = new MessageQueue(mqName, false, false, QueueAccessMode.SendAndReceive)) { ret = mq.GetAllMessages(); mq.Close(); } return ret; } }
public static void StartProcessing() { string queuePath = @".\private$\BroccoliEmails"; QueueService.InsureQueueExists(queuePath); msgQ = new MessageQueue(queuePath); msgQ.Formatter = new BinaryMessageFormatter(); msgQ.MessageReadPropertyFilter.SetAll(); var messages = msgQ.GetAllMessages(); foreach (var message in messages) { var msg = (EmailMessage) message.Body; msgQ_Send(msg); } msgQ.Close(); }
static void Exercise1() { Console.WriteLine("Exercise1"); MessageQueue queue = new MessageQueue(privateQueueName); List<Record> records = new List<Record>(); for (Int64 i = 0; i < Int16.MaxValue; i++) { Record record = new Record(); record.Subject = "Record Subject " + i; record.Body = "Record Body " + i; records.Add(record); } queue.Send(records); queue.Close(); Console.WriteLine("End"); Console.WriteLine(); }
public static int GetMessageQueueCount(string queue) { string mqName = CreateMessageQueueName(queue); if (!MessageQueue.Exists(mqName)) { MessageQueue.Create(mqName, true); return 0; } else { int ret = 0; using (MessageQueue mq = new MessageQueue(mqName, false, false, QueueAccessMode.SendAndReceive)) { ret = mq.GetAllMessages().Length; mq.Close(); } return ret; } }
public override bool Send(object obj) { try { // open the queue MessageQueue mq = new MessageQueue(url); // set the message to durable. mq.DefaultPropertiesToSend.Recoverable = true; // set the formatter to Binary if needed, default is XML //mq.Formatter = new BinaryMessageFormatter(); // send the job object mq.Send(obj, "Message Test"); mq.Close(); return true; } catch (Exception e) { return false; } }
public static void QueueCommand(ICommand c) { try { // open the queue MessageQueue mq = new MessageQueue(_queuePath); // set the message to durable. mq.DefaultPropertiesToSend.Recoverable = true; // set the formatter to Binary, default is XML mq.Formatter = new BinaryMessageFormatter(); // send the command object mq.Send(c, "Command Message"); mq.Close(); } catch (Exception e) { // TODO: Log exception } }
/// <summary> /// Queues the command. /// </summary> /// <param name="c">The c.</param> public static void QueueCommand(ICommand c) { try { // open the queue var mq = new MessageQueue(QueuePath) {DefaultPropertiesToSend = {Recoverable = true}, Formatter = new BinaryMessageFormatter()}; // set the message to durable. // set the formatter to Binary, default is XML // send the command object mq.Send(c, "Command Message"); mq.Close(); } catch (Exception e) { Log.ErrorFormat("Error: {0}", e.Message); } }
protected override void Worker(string tag, string result) { try { // open the queue MessageQueue mq = new MessageQueue(url); // set the message to durable. mq.DefaultPropertiesToSend.Recoverable = true; // set the formatter to Binary if needed, default is XML //mq.Formatter = new BinaryMessageFormatter(); // send the job object mq.Send(result, tag); mq.Close(); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.StackTrace); System.Diagnostics.Trace.WriteLine(e.Message); } }
public void LogMessageToMSMQ() { string path = @"FormatName:DIRECT=OS:" + CommonUtil.MessageQueuePath; MsmqSinkData sinkParams = new MsmqSinkData("MsmqSink"); sinkParams.QueuePath = path; sinkParams.MessagePriority = MessagePriority.Low; MsmqSink sink = CreateSink(sinkParams); CommonUtil.SendTestMessage(sink); MessageQueue mq = new MessageQueue(path); mq.MessageReadPropertyFilter.Priority = true; Message msg = mq.Receive(new TimeSpan(0, 0, 1)); msg.Formatter = new XmlMessageFormatter(new string[] {"System.String,mscorlib"}); mq.Close(); mq = null; Assert.AreEqual(MessagePriority.Low, msg.Priority); Assert.AreEqual(CommonUtil.FormattedMessage, msg.Body.ToString()); }
public void InsertMessageinQueue() { try { var msmq = new MessageQueue(queueFullName); var msg = new Message(); msg.Body = "SampleMessage "; msg.Label = "Msg" + i.ToString(); ++i; msmq.Send(msg, System.Messaging.MessageQueueTransactionType.Single); msmq.Close(); Console.WriteLine(i); System.Threading.Thread.Sleep(2000); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public override void Init() { base.Init(); _consumers = new Hashtable(); _msmqSettings = DestinationDefinition.Properties.Msmq; if (_msmqSettings != null) { MessageQueue.EnableConnectionCache = false; log.Debug(__Res.GetString(__Res.Msmq_StartQueue, _msmqSettings.Name)); _messageQueue = new MessageQueue(_msmqSettings.Name); string messageFormatterName = MsmqProperties.BinaryMessageFormatter; if (!string.IsNullOrEmpty(_msmqSettings.Formatter)) messageFormatterName = _msmqSettings.Formatter; log.Debug(__Res.GetString(__Res.Msmq_InitFormatter, messageFormatterName)); if (messageFormatterName == MsmqProperties.BinaryMessageFormatter) { _messageFormatter = new BinaryMessageFormatter(); _messageQueue.Formatter = _messageFormatter; } else if (messageFormatterName.StartsWith(MsmqProperties.XmlMessageFormatter)) { string[] formatterParts = messageFormatterName.Split(new char[] { ';' }); Type[] types; if (formatterParts.Length == 1) types = new Type[] { typeof(string) }; else { types = new Type[formatterParts.Length - 1]; for (int i = 1; i < formatterParts.Length; i++) { Type type = ObjectFactory.Locate(formatterParts[i]); if (type != null) types[i - 1] = type; else log.Error(__Res.GetString(__Res.Type_InitError, formatterParts[i])); } } _messageFormatter = new XmlMessageFormatter(types); _messageQueue.Formatter = _messageFormatter; } else { log.Error(__Res.GetString(__Res.Type_InitError, messageFormatterName)); _messageQueue.Close(); _messageQueue = null; } } else log.Error(__Res.GetString(__Res.ServiceAdapter_MissingSettings)); }
public void SetTimeout() { m_Queue.Close(); m_Queue.Refresh(); }