本文整理汇总了C#中System.Messaging.MessageQueue.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# MessageQueue.Receive方法的具体用法?C# MessageQueue.Receive怎么用?C# MessageQueue.Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Messaging.MessageQueue
的用法示例。
在下文中一共展示了MessageQueue.Receive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine("Simple Text");
Console.WriteLine("Input for MSMQ Message:");
string input = Console.ReadLine();
MessageQueue queue = new MessageQueue(@".\private$\test");
queue.Send(input);
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
Console.WriteLine("Output for MSMQ Queue");
Console.WriteLine(queue.Receive().Body.ToString());
Console.ReadLine();
Console.WriteLine("Complex Text");
User tester = new User();
tester.Birthday = DateTime.Now;
tester.Name = "Test Name";
queue.Send(tester);
Console.WriteLine("Output for MSMQ Queue");
User output = (User)queue.Receive().Body;
Console.WriteLine(output.Birthday.ToShortDateString());
Console.ReadLine();
}
示例2: When_a_failed_message_arrives_to_error_queue_will_have_another_message_explaining_what_happened
public void When_a_failed_message_arrives_to_error_queue_will_have_another_message_explaining_what_happened()
{
int count = 0;
Transport.MessageArrived += o =>
{
Interlocked.Increment(ref count);
throw new InvalidOperationException("Operation is not valid due to the current state of the object.");
};
Transport.Send(TestQueueUri, new object[] { DateTime.Today });
using (var errorQueue = new MessageQueue(testQueuePath + ";errors"))
{
errorQueue.Formatter = new XmlMessageFormatter(new[] { typeof(string) });
errorQueue.MessageReadPropertyFilter.SetAll();
errorQueue.Peek(TimeSpan.FromSeconds(30));//for debugging
var messageCausingError = errorQueue.Receive(TimeSpan.FromSeconds(30));
Assert.NotNull(messageCausingError);
errorQueue.Peek(TimeSpan.FromSeconds(30));//for debugging
var messageErrorDescription = errorQueue.Receive(TimeSpan.FromSeconds(30));
var error = (string)messageErrorDescription.Body;
Assert.Contains(
"System.InvalidOperationException: Operation is not valid due to the current state of the object.",
error);
Assert.Equal(
messageCausingError.Id,
messageErrorDescription.CorrelationId);
}
}
示例3: Main
static void Main(string[] args)
{
CitaDAO dao = new CitaDAO();
string rutaCola = @".\private$\CitaRecibida";
if (MessageQueue.Exists(rutaCola) == true)
{
MessageQueue cola = new MessageQueue(rutaCola);
Message[] msgs = cola.GetAllMessages();
Cita _cita = new Cita();
if (cola.GetAllMessages().Count() > 0)
{
foreach (Message msg in cola.GetAllMessages())
{
msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(Cita) });
_cita = (Cita)msg.Body;
if (dao.Obtener(_cita.IdCita) == null)
{
dao.Crear(_cita);
}
else
{
dao.Modificar(_cita);
}
cola.Receive();
}
}
}
}
示例4: listar
public List<PromocionBE> listar(PromocionBE objPromocionBE)
{
string rutaColaIn = @".\private$\fidecine_promocion";
if (!MessageQueue.Exists(rutaColaIn))
MessageQueue.Create(rutaColaIn);
MessageQueue colaIn = new MessageQueue(rutaColaIn);
colaIn.Formatter = new XmlMessageFormatter(new Type[] { typeof(Promocion) });
Message mensajeIn = colaIn.Receive();
Promocion obj = (Promocion)mensajeIn.Body;
new PromocionDAO().insertar(obj);
List<PromocionBE> listaPromocion = new List<PromocionBE>();
PromocionBE tempPromocionBE = null;
foreach (Promocion objPromocion in new PromocionDAO().listar(objPromocionBE.VigenciaInicio, objPromocionBE.VigenciaFin))
{
tempPromocionBE = new PromocionBE();
tempPromocionBE.IdPromocion = objPromocion.IdPromocion;
tempPromocionBE.ProductoNombre = objPromocion.Producto.Nombre;
tempPromocionBE.Puntos = objPromocion.Puntos;
tempPromocionBE.VigenciaInicio = objPromocion.vigenciaInicio.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
tempPromocionBE.VigenciaFin = objPromocion.vigenciaFin.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
listaPromocion.Add(tempPromocionBE);
}
return listaPromocion;
}
示例5: btQueue_Click
private void btQueue_Click(object sender, EventArgs e)
{
MessageQueue myQueue = new MessageQueue(".\\Private$\\MyTestQueue");
//myQueue.Formatter = new BinaryMessageFormatter();
myQueue.Formatter = new ActiveXMessageFormatter();
try
{
// Receive and format the message.
System.Messaging.Message myMessage = myQueue.Receive();
String sBody = (String)myMessage.Body;
MessageBox.Show(sBody);
/*// Display message information.
Console.WriteLine("Order ID: " +
myOrder.orderId.ToString());
Console.WriteLine("Sent: " +
myOrder.orderTime.ToString());*/
}
catch (MessageQueueException)
{
// Handle Message Queuing exceptions.
}
// Handle invalid serialization format.
catch (InvalidOperationException e2)
{
Console.WriteLine(e2.Message);
}
int k = 3;
}
示例6: StringMessageFormatter
public void StringMessageFormatter()
{
var ids = new List<string>();
var mq = new MessageQueue(@".\private$\QMM_");
mq.Formatter = new StringMessageFormatter();
mq.Send("12345");
mq.Send("23456");
mq.Dispose();
mq = null;
mq = new MessageQueue(@".\private$\QMM_");
for (int i = 0; i < 3; i++)
{
Message msg = null;
try
{
msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
if (msg != null)
{
msg.Formatter = new StringMessageFormatter();
Console.WriteLine(msg.Body);
}
}
}
示例7: WriteReadMessage
public void WriteReadMessage()
{
var ids = new List<string>();
var mq = new MessageQueue(@".\private$\QMM_");
mq.Send("12345");
mq.Send("23456");
var msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
if (msg != null)
Console.WriteLine(msg.Body);
mq.Dispose();
mq = null;
mq = new MessageQueue(@".\private$\QMM_");
msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
if (msg != null)
{
msg.Formatter = new XmlMessageFormatter(new Type[] {typeof (string)});
Console.WriteLine(msg.Body);
}
}
示例8: MangledMessageIsNotReceived
public void MangledMessageIsNotReceived()
{
using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
{
var transaction = new MessageQueueTransaction();
transaction.Begin();
messageQueue.Send(new Message
{
Extension = Encoding.UTF32.GetBytes("this is definitely not valid UTF8-encoded JSON")
}, transaction);
transaction.Commit();
}
Thread.Sleep(5000);
CleanUpDisposables();
using (var messageQueue = new MessageQueue(MsmqUtil.GetPath(_inputQueueName)))
{
messageQueue.MessageReadPropertyFilter = new MessagePropertyFilter
{
Extension = true
};
var transaction = new MessageQueueTransaction();
transaction.Begin();
var message = messageQueue.Receive(transaction);
Assert.That(message, Is.Not.Null);
Assert.That(Encoding.UTF32.GetString(message.Extension), Is.EqualTo("this is definitely not valid UTF8-encoded JSON"));
transaction.Commit();
}
}
示例9: LogTwoMessagesToQueueAndBeAbleToReadBothOfThem
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());
}
}
示例10: ReceiveMessage
public Object ReceiveMessage(MessageQueue queue)
{
queue.Formatter = new MsmqMessageFormatter();
var mqMessage = queue.Receive();
return mqMessage.Body;
}
示例11: ReceiveMessage
public static Message ReceiveMessage(string queuePath, int time2Wait, out string errorMessage)
{
// Define default errorMessage
errorMessage = null;
// Connect to the a queue on the local computer and set the formatter to indicate body contains a binary object
var myQueue = new MessageQueue(queuePath)
{
Formatter = new BinaryMessageFormatter()
};
// Receive and format the message.
Message myMessage = null;
var timeout = TimeSpan.Zero;
if (time2Wait > 0)
timeout = new TimeSpan(0, 0, time2Wait);
try
{
myMessage = myQueue.Receive(timeout);
}
catch (MessageQueueException e)
{
if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
{
errorMessage = e.Message;
}
}
return myMessage;
}
示例12: Main
static void Main(string[] args)
{
SolicitudServicioData oSolicitudServicioData = new SolicitudServicioData();
string rutaCola = @".\private$\SolicitudServicioRecibida";
if (MessageQueue.Exists(rutaCola) == true)
{
MessageQueue cola = new MessageQueue(rutaCola);
Message[] msgs = cola.GetAllMessages();
SolicitudServicioDTO oSolicitudServicioDTO = new SolicitudServicioDTO();
if (cola.GetAllMessages().Count() > 0)
{
foreach (Message msg in cola.GetAllMessages())
{
msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(SolicitudServicioDTO) });
oSolicitudServicioDTO = (SolicitudServicioDTO)msg.Body;
if (oSolicitudServicioData.Get(oSolicitudServicioDTO.SolicitudServicioId) == null)
{
oSolicitudServicioData.Add(oSolicitudServicioDTO);
}
else
{
oSolicitudServicioData.Update(oSolicitudServicioDTO);
}
cola.Receive();
}
}
}
}
示例13: Receive
public Message Receive(MessageQueue queue, TimeSpan timeout)
{
var message = queue.Receive(timeout, MessageQueueTransactionType.Automatic);
_suppressedScope = new TransactionScope(TransactionScopeOption.Suppress, TimeSpan.Zero);
return message;
}
示例14: GetElementFromDestination
public string GetElementFromDestination(string pQueuePach)
{
System.Messaging.Message sourceMessage;
string str="";
try
{
destinationQueue = new System.Messaging.MessageQueue(pQueuePach);
((XmlMessageFormatter)destinationQueue.Formatter).TargetTypeNames = new string[]{"System.String"};
if(destinationQueue.GetAllMessages ().Length >0)
{
sourceMessage = destinationQueue.Receive(System.Messaging.MessageQueueTransactionType.Automatic);
// destinationQueue.Formatter = new XmlMessageFormatter(new Type[] {typeof(String)});
((XmlMessageFormatter)destinationQueue.Formatter).TargetTypeNames = new string[]{"Empleado"};
str = (string)sourceMessage.Body;
}
return str;
}
catch(MessageQueueException e)
{
throw e;
}
}
示例15: enviarPromociones
public string enviarPromociones()
{
string resultado = string.Empty;
try
{
string rutaCola = @".\private$\CitasClinica";
if (!MessageQueue.Exists(rutaCola))
MessageQueue.Create(rutaCola);
MessageQueue cola = new MessageQueue(rutaCola);
cola.Formatter = new XmlMessageFormatter(new Type[] { typeof(Cita) });
foreach (var msj in cola.GetAllMessages())
{
Message mensaje = cola.Receive();
Cita citaBE = (Cita)mensaje.Body;
enviarCorreo(citaBE);
}
resultado = "Se envio las promociones OK";
}
catch (Exception)
{
resultado = "No se enviaron las promociones";
}
return resultado;
}