MSMQ 멀티 캐스트 기능을 사용하여 게시자 및 구독자 모델을 만들고 싶습니다. 난 이미 성공없이 링크에서 답 따랐다 MSMQ를 - 멀티 캐스트 대기열에서 수신 할 수 전송 및 로컬 컴퓨터로 수신하기 메시지.
보내는 사람:
using (var helloQueue = new MessageQueue("FormatName:MULTICAST=234.1.1.1:8001"))
{
while (true)
{
var stopWatch = new Stopwatch();
stopWatch.Start();
for (var i = 0; i < 1000; i++)
{
SendMessage(helloQueue,
string.Format("{0}: msg:{1} hello world ", DateTime.UtcNow.Ticks, i));
}
stopWatch.Stop();
Console.ReadLine();
Console.WriteLine("====================================================");
Console.WriteLine("[MSMQ] done sending 1000 messages in " + stopWatch.ElapsedMilliseconds);
Console.WriteLine("[MSMQ] Sending reset counter to consumers.");
SendMessage(helloQueue, "reset");
Console.ReadLine();
}
}
리시버:
int messagesReceived = 0;
var messages = new Queue<string>(5000);
var filePath = typeof(Subscriber).FullName + ".txt";
var path = @".\private$\hello-queue";
using (var helloQueue = new MessageQueue(path))
{
helloQueue.MulticastAddress = "234.1.1.1:8001";
while (true)
{
var message = helloQueue.Receive();
if (message == null)
return;
var reader = new StreamReader(message.BodyStream);
var body = reader.ReadToEnd();
messagesReceived += 1;
messages.Enqueue(body);
Console.WriteLine(" [MSMQ] {0} Received {1}", messagesReceived, body);
if (string.CompareOrdinal("reset", body) == 0)
{
messagesReceived = 0;
File.WriteAllText(filePath, body);
messages.Clear();
}
}
}
이벤트 로그에 IP가 표시된 multicastbind 레지스트리에 키를 추가했습니다 (확실하지 않음). 우리가 큐에 지정하는 MulticastAddress는 특정한 것입니까, 아니면 지정된 범위의 어떤 것을 사용할 수 있습니까?
이것은 포트 번호를 변경하여 해결되었습니다. 휴식은 좋았습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다