I am using .NET 3.5 to send message to active mq and i have a java listener which process these messages from the queue.
Header contains
userId - long
type - string
isAdd-bool
Listener is expecting payload to be of datatype long. So i should send datatype long in payload.
Here is the code that i am using to post message to active mq.
string payLoad = "123";
IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
using (IConnection connection = factory.CreateConnection())
{
using (ISession session = connection.CreateSession())
{
IDestination destination = Apache.NMS.Util.SessionUtil.GetDestination(session
, "Message.AddUser");
using (IMessageProducer producer =
session.CreateProducer(destination))
{
// Start the connection so that messages will be processed.
connection.Start();
//here i need to pass payload as datatype "long"
ITextMessage request = session.CreateTextMessage(payLoad);
request.Properties["userid"] = 123;
request.Properties["type"] = "USER";
request.Properties["isAdd"] = true;
producer.Send(request);
}
}
}
Currently as per the code, i am sending string as payload.
ITextMessage request = session.CreateTextMessage(payLoad);
How can i change this code to send payload as data type long? i tried to send payload as object. But i am getting an error when listener picks this message. Error: Invalid stream header is corrupted.
As per the comment, i used IStreamMessage
int userId = 123;
IStreamMessage message = session.CreateStreamMessage()
message.WriteInt64((long)idToUpdate);
message.Properties.SetLong("userId", (long)userId);
message.Properties.SetString("type", "USER");
message.Properties.SetBool("isDelete", true);
Then i looked at tomcat logs and this is what i could see, Header is missing in this. I have only Payload
[Payload=ActiveMQStreamMessage {commandId = 5, responseRequired = true, messageId = ID:XXXXX-60790-
stamp=1400070001928, jms_redelivered=false, userId=123, type=USER, jms_messageId=ID:XXXXX-60790-635356865723233336-0:0:1:2:1}]
As this was not working, i tried using ITextMessage.
int userId = 123;
ITextMessage request = session.CreateTextMessage();
request.Text = idToUpdate.ToString();
request.Properties["companyId"] = (long)userId;
request.Properties["type"] = "USER";
request.Properties["isDelete"] = true;
Here is what i could see in the log.
[Payload=46][Headers={timestamp=1400072608501, id=dde638d2-4036-4e81-a3c8-97937ac11087, isDelete=true, jms_timestamp=1400072608280, jms_redelivered=false, userId=1, type=USER, jms_messageId=ID:xxxx-53593-635356892076410652-0:0:1:2:1}]
I am using Sprint Integration and listener is expecting List as the input parameter
public void updateUser(Message<List<Long>> message) {
Long userId = (Long) message.getHeaders().get("userId");
for (Long userId : message.getPayLoad()) { // exception is thrown here "Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long"
//doing somethign here with userid
}
}
How can send payload which is of long datatype?