我正在尝试学习MSMQ,我开始做两个简单的控制台应用程序。发射器和接收器。
首先,这是发射器代码:
static void Main(string[] args)
{
try
{
if (MessageQueue.Exists(path))
{
mqueue = new MessageQueue(path);
}
else
{
mqueue = MessageQueue.Create(path);
}
Timer timer = new Timer(timerCallback, null, 3000, 3000);
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
System.Console.ReadLine();
}
}
static void timerCallback(object state)
{
Student student = new Student(randomString(), randomString(), randomString());
mqueue.Send(student);
System.Console.WriteLine("sent: {0}", student.ToString());
}
接收者:
static void Main(string[] args)
{
try
{
if (MessageQueue.Exists(path))
{
mqueue = new MessageQueue(path);
}
else
{
mqueue = MessageQueue.Create(path);
}
Type [] supportedTypes = {typeof(Student)};
mqueue.Formatter = new XmlMessageFormatter(supportedTypes);
mqueue.BeginReceive(new TimeSpan(0,0,5000), mqueue, new AsyncCallback(messageReceived));
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
}
finally
{
System.Console.ReadLine();
}
}
该应用程序运行良好,但我想将通讯渠道更改为TcpChannel/ HttpChannel
。知道怎么做吗?
答案 0 :(得分:1)
CodeProject: creating a WCF service with MSMQ为您提供了一个关于msmq的精彩教程。一些搜索让我得出结论,这只能在wcf中使用,但我可能是错的。