MVC를 보낸 사람 응용 프로그램으로 사용하는 Apache ActiveMQ에 메시지를 대기시키고 자하고 Apache ActiveMQ에 대한 수신기로 C#으로 작성된 창 서비스가 있습니다. 하지만 위의 수신기에서 메시지를 읽는 동안 예외가 발생합니다.Spring.net을 사용하는 ActiveMQ 및 .NET을 사용하는 복잡한 유형의 메시징 작동하지 않음
발신자 MVC 코드.
public void GenerateMQMessages(EmailModel mail)
{
try
{
//// Create the Connection Factory
ConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");
NmsTemplate nmsTemplate = new NmsTemplate(factory);
nmsTemplate.Send("EmailQueue", new GenericMessageCreator<dummyClass>(new dummyClass { Prop1 = 1, Prop2 = "Hello There" }));
}
catch (System.Exception e)
{
}
}
public class GenericMessageCreator<T> : IMessageCreator
{
public T Body { get; set; }
public GenericMessageCreator(T body)
{
this.Body = body;
}
IMessage IMessageCreator.CreateMessage(ISession session)
{
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
msg.Body = this.Body;
return msg;
}
}
[Serializable]
public class dummyClass : ISerializable
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
//throw new NotImplementedException();
}
}
C# Windows 서비스 코드. 메시지 나 개체를 확장하면 윈도우 서비스 측에
protected override void OnStart(string[] args)
{
try
{
//// Create the Connection factory
ConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.ConnectionFactory = factory;
listenerContainer.DestinationName = "EmailQueue";
listenerContainer.MessageListener = new GenericMessageListener<dummyClass>();
listenerContainer.AfterPropertiesSet();
}
catch (System.Exception e)
{
}
}
public class GenericMessageListener<T> : IMessageListener
{
public void OnMessage(IMessage message)
{
try
{
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
if (msg != null)
{
T body = (T)msg.Body;
//dummyClass body = (dummyClass)msg.Body;
typeof(T).GetProperties()
.ToList()
.ForEach(prop =>
{
var p = string.Format("{0} = {1},", prop.Name, prop.GetValue(body, new object[] { }));
});
}
}
catch (Exception e)
{
}
}
}
[Serializable]
public class dummyClass : ISerializable
{
public int Prop1 { get; set; }
public string Prop2 { get; set; }
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
//throw new NotImplementedException();
}
}
예외 '는 ((Apache.NMS.ActiveMQ.Commands.ActiveMQObjectMessage)는 (메시지)). 바디'형식의 예외가 발생했습니다 '들은 System.Runtime.Serialization .SerializationException '
이 문제를 해결 했습니까? – irperez