Hello!
I'm trying to send a JSON format through ActiveMQ (C# Console Application), but right now I'm stock in the following:
1) If I send the direct JSON serialization (as string) the system adds backward slashes "\" to the text, which makes my listener unable to process the information.
2) I can remove the backwar slashes by doing a JToken Parse, but I cannot send the var on ActiveMQ (ITextMessage requests a String, I'm sending a JToken) and of course if I do cast of the JToken to string I found again the backward slashes "\"
Any clue on how I can achieve my goal???
What I have tried:
Here is my current code:
String IP = "172.29.75.43:61616";
String QueuesNameESF = "queue://MES2WMSTVOFFLINE";
try
{
Uri _uri = new Uri(String.Concat("activemq:tcp://" + IP));
IConnectionFactory factory = new ConnectionFactory(_uri);
using (IConnection conn = factory.CreateConnection())
{
using (ISession session = conn.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, QueuesNameESF);
using (IMessageProducer producer = session.CreateProducer(destination))
{
SqlConnection dbConnection = new SqlConnection("Integrated Security=false;Data Source=smxsql08svr01;initial catalog=BSS;user id=sa;password=newshamu;Max Pool Size=75000");
SqlConnection internalConnection = new SqlConnection("Integrated Security=false;Data Source=smxsql08svr01;initial catalog=BSS;user id=sa;password=newshamu;Max Pool Size=75000");
String SearchPallet;
SqlCommand cmd = new SqlCommand();
dbConnection.Open();
SearchPallet = "";
SearchPallet = "Select Replace(Replace(Replace((Convert(varchar,GETDATE(),120) + Palletnum),'-',''),' ',''),':','') as 'ID', ";
SearchPallet += "'Y' as 'beFull','ZJ' as 'ext1','' as 'ext2','Y'as 'isCM',Part_Number as 'itemCode',linea as 'line',";
SearchPallet += "Case When len(Part_Number) = 12 then RIGHT(Part_Number,7) else RIGHT(Part_Number,8) end as 'lot',";
SearchPallet += "Palletnum as 'mainPallet',GETDATE() as 'sendTime','BSS' as'sender','8170' as'werks' From Finishgoods ";
SearchPallet += "Where PalletNum = @Palletnum GROUP by PalletNum,Part_Number,linea";
cmd.CommandText = SearchPallet;
cmd.Connection = dbConnection;
cmd.Parameters.Add("@Palletnum", SqlDbType.VarChar).Value = "PT01929734";
SqlDataReader rdr = cmd.ExecuteReader();
FirstLevel product = new FirstLevel();
if (rdr.Read())
{
product.guid = rdr.GetValue(0).ToString();
product.beFull = rdr.GetValue(1).ToString();
SecondLevel msg = new SecondLevel();
msg.carton = rdr.GetValue(8).ToString();
List<ThirdLevel> serials = new List<ThirdLevel>();
ThirdLevel sn = new ThirdLevel();
String SearchSN = "Select barcodenum as 'serNo',''as 'ext1',''as 'ext2' From Finishgoods where palletnum = @palletnum";
SqlCommand cmd_sn = new SqlCommand();
internalConnection.Open();
cmd_sn.Connection = internalConnection;
cmd_sn.CommandText = SearchSN;
cmd_sn.Parameters.Add("@Palletnum", SqlDbType.VarChar).Value = "PT01929734";
SqlDataReader rdr_sn = cmd_sn.ExecuteReader();
while (rdr_sn.Read())
{
sn.serNo = rdr_sn.GetValue(0).ToString();
sn.ext1 = rdr_sn.GetValue(1).ToString();
sn.ext2 = rdr_sn.GetValue(2).ToString();
serials.Add(sn);
}
rdr_sn.Close();
cmd_sn.Parameters.Clear();
cmd_sn.Dispose();
internalConnection.Close();
msg.serNoMsg = serials;
product.crtonMsg = msg;
product.ext1 = rdr.GetValue(2).ToString();
product.ext2 = rdr.GetValue(3).ToString();
product.isCM = rdr.GetValue(4).ToString();
product.itemCode = rdr.GetValue(5).ToString();
product.line = rdr.GetValue(6).ToString();
product.lot = rdr.GetValue(7).ToString();
product.mainPallet = rdr.GetValue(8).ToString();
product.sendTime = rdr.GetValue(9).ToString();
product.sender = rdr.GetValue(10).ToString();
product.werks = rdr.GetValue(11).ToString();
}
rdr.Close();
string json_ = JsonConvert.SerializeObject(product);
var json = JToken.Parse(json_);
conn.Start();
ITextMessage request = session.CreateTextMessage(json);
producer.Send(request);
}
Console.WriteLine("send succeed");
Console.ReadLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Receive Failed");
Console.ReadLine();
}