private static void SendContactObjectAsMessage(bool sendObject) { var queueName = ConfigurationManager.AppSettings["StronglyTypedQueue"]; Contact contact = new Contact() { FirstName = "Rajesh", Id = 100, LastName = "Mishra", Guid = new Guid() }; Message myMessage = new Message(); if (sendObject) { //myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(Contact) }); myMessage.Formatter = new BinaryMessageFormatter(); myMessage.Body = contact; myMessage.Label = "Contact"; } else { myMessage.Formatter = new BinaryMessageFormatter(); myMessage.Body = "This is string Message " + DateTime.Now.ToString(); myMessage.Label = "StringMessage"; } myMessage.UseJournalQueue = true; myMessage.UseDeadLetterQueue = true; myMessage.Recoverable = true; myMessage.AdministrationQueue = new MessageQueue(ConfigurationManager.AppSettings["AckQueueName"].ToString()); myMessage.AcknowledgeType = AcknowledgeTypes.PositiveArrival | AcknowledgeTypes.FullReceive; IMSMQFacoty queueOperation = new MSMQFacoty(); queueOperation.EnqueMessage("StronglyTypedQueue", myMessage); Console.WriteLine("Message Sent"); Console.ReadLine(); }
private static void ReadStronglyTypedMessages() { var queueName = ConfigurationManager.AppSettings["StronglyTypedQueue"]; IMSMQFacoty queueOperation = new MSMQFacoty(); var obj = queueOperation.DequeBinaryMessage("StronglyTypedQueue"); if (obj != null && obj.Label == "Contact") { var data = (Contact)obj.Body; StringBuilder sb = new StringBuilder(); sb.Append(data.FirstName + ";"); sb.Append(data.LastName + ";"); sb.Append(data.Id.ToString() + ";"); sb.Append(data.Guid.ToString() + ";"); Console.WriteLine(sb); } else if (obj != null && obj.Label == "StringMessage") { var data = Convert.ToString(obj.Body); Console.WriteLine(data); } else { Console.WriteLine("No Messages to read"); } }
internal static void SendMessage() { IMSMQFacoty queueOperation = new MSMQFacoty(); queueOperation.EnqueMessage("Queue", string.Format("Test message coming from ClientA at {0}", DateTime.UtcNow)); Console.ReadLine(); }
internal static void ProcessMessage() { try { IMSMQFacoty queueOperation = new MSMQFacoty(); int count = queueOperation.ProcessMessage("CorrelationRequest", "CorrelationResponse"); Console.WriteLine("{0} messages processed", count); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); logger.LogError(ex.Message); } }
internal static void SendMessage() { try { int count = 10; IMSMQFacoty queueOperation = new MSMQFacoty(); Console.Write("Enter message for processing : "); for (int index = 0; index < count; index++) { string message = Console.ReadLine(); queueOperation.EnqueMessage("CorrelationRequest", message); } Console.WriteLine("{0} messages sent for processing", count); Console.ReadLine(); } catch (Exception ex) { logger.LogError(ex.Message); throw; } }
internal static void ReceiveProcessedMessage() { try { IMSMQFacoty queueOperation = new MSMQFacoty(); string[] allMessage = queueOperation.ShowProcessedMessage("CorrelationRequest", "CorrelationResponse"); for (int index = 0; index < allMessage.Length; index++) { if (!string.IsNullOrEmpty(allMessage[index])) { Console.WriteLine(allMessage[index]); Console.WriteLine(); } } Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); logger.LogError(ex.Message); throw; } }