입력을 사용하여 주제에 메시지를 보내고 주제에 게시 된 메시지를 표시하는 간단한 애플리케이션을 작성하려고합니다. 두 개의 명령 줄 실행 파일이 있습니다. 하나는 게시자 용이고 다른 하나는 구독자 용입니다. 주제에 메시지를 게시 할 때 해당 주제에 메시지가 전송 된 것을 볼 수 있습니다.EMS.NET API를 사용하여 주제에서 메시지를 가져올 수 없습니다.
다음 명령은 주제에 대한 메시지가 있음을 보여줍니다 (F1.gif 참조) -
show stat EMS.Test.Topic
다음 명령은 메시지가 가입자에 의해 소비지고 있음을 보여준다 (참조 F2.gif)
show stat consumers topic=EMS.Test.Topic
그러나 EMS .NET API 메시지를 검색 할 수 없습니다. Message msg = subscriber.Receive();
에 붙어 있습니다. 메시지를 게시 할 때 사용되므로 연결 세부 정보 및 인증 세부 정보가 올바른지 확인했습니다.
public string ReceiveMessagesFromTopic(string topicName)
{
TopicConnection connection = null;
string messageFromPublisher = string.Empty;
try
{
var factory = new TIBCO.EMS.TopicConnectionFactory(serverUrl);
connection = factory.CreateTopicConnection(userName, password);
TopicSession session = connection.CreateTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.CreateTopic(topicName);
TopicSubscriber subscriber = session.CreateSubscriber(topic);
connection.Start();
while (true)
{
Message msg = subscriber.Receive();
if (msg == null)
{
break;
}
if (msg is TextMessage)
{
TextMessage tm = (TextMessage) msg;
messageFromPublisher = tm.Text;
}
}
connection.Close();
}
catch (EMSException e)
{
if (connection!=null)
{
connection.Close();
}
throw;
}
return messageFromPublisher;
}
안녕하세요, 심지어 나를 위해, 컨트롤은 subscriber.receive에서 중지됩니다. if (msg == null) 자체는 라인에 가지 않습니다. 주제에 메시지가 없으면 컨트롤은 다음 줄 자체로 이동하지 않습니다. 위의 해결 방법이 정확한지 궁금합니다. – user1447718