using Apache.NMS;
|
using Apache.NMS.ActiveMQ;
|
using Rhea.Common;
|
using Tiger.Model;
|
using Tiger.Model.SeaStone.Shelf;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using System.IO;
|
using Newtonsoft.Json;
|
using Tiger.Business.WMS.Seastone;
|
using Tiger.IBusiness;
|
|
namespace Tiger.Business.WMS.Transaction
|
{
|
/// <summary>
|
/// WMS事务基类
|
/// </summary>
|
public abstract class WMSTransactionBase : TransactionBase, IWMSTransaction
|
{
|
/// <summary>
|
/// WMS事务基类
|
/// </summary>
|
public WMSTransactionBase()
|
{
|
//MQTTThread = new Thread(new ThreadStart(MQTT));
|
//MQTTThread.Start();
|
//Logger.Console.Info($"Start Transaction MQTT Thread(ID: {TransID}]");
|
}
|
|
/// <summary>
|
/// 关闭事务
|
/// </summary>
|
/// <param name="needSaveHistoryLog"></param>
|
/// <returns></returns>
|
public override bool Close(bool needSaveHistoryLog = false)
|
{
|
return base.Close(needSaveHistoryLog);
|
}
|
|
public override void Dispose()
|
{
|
try
|
{
|
//MQTTThread?.Abort();
|
//删除使用的MQTT Topic
|
//MQTTHelper.DeleteTopic(TransID);
|
Logger.Console.Info($"Dispose Transaction(ID: {TransID}]");
|
}
|
catch (System.Exception ex)
|
{
|
Logger.Console.Fatal(ex, $"Dispose Transaction Exception(ID: {TransID}]");
|
}
|
base.Dispose();
|
}
|
|
#region WMS业务
|
/// <summary>
|
/// 执行中条码
|
/// </summary>
|
public string ProcessingSn { get; set; }
|
|
#endregion
|
|
#region MQTT
|
private Thread MQTTThread;
|
private void MQTT()
|
{
|
try
|
{
|
//Create the Connection factory
|
IConnectionFactory factory = new ConnectionFactory(ApiConfig.Configuration["MQTTService:IPAddress"]);
|
|
//Create the connection
|
using (IConnection connection = factory.CreateConnection())
|
{
|
connection.ClientId = $"{Environment.MachineName}-Receive-{TransID}";
|
connection.Start();
|
|
//Create the Session
|
using (ISession session = connection.CreateSession())
|
{
|
//Create the Consumer
|
IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(TransID));
|
consumer.Listener += new MessageListener(consumer_Listener);
|
while (!IsFinished)
|
{
|
|
}
|
}
|
connection.Stop();
|
connection.Close();
|
}
|
}
|
catch (System.Exception e)
|
{
|
Console.WriteLine(e.Message);
|
}
|
}
|
private string ReceiveMsg;
|
private void consumer_Listener(IMessage message)
|
{
|
try
|
{
|
ITextMessage msg = (ITextMessage)message;
|
Console.WriteLine("MQTT Receive: " + msg.Text);
|
}
|
catch (System.Exception e)
|
{
|
Console.WriteLine(e.Message);
|
}
|
}
|
|
#endregion
|
}
|
}
|