static void Main() { //Create MDSClient object to connect to DotNetMQ //Name of this application: Application1 var mdsClient = new MDSClient("Application1"); //Connect to DotNetMQ server mdsClient.Connect(); Console.WriteLine("Write a text and press enter to send to Application2. Write 'exit' to stop application."); while (true) { //Get a message from user var messageText = Console.ReadLine(); if (string.IsNullOrEmpty(messageText) || messageText == "exit") { break; } //Create a DotNetMQ Message to send to Application2 var message = mdsClient.CreateMessage(); //Set destination application name message.DestinationApplicationName = "Application2"; //message.DestinationServerName = "this_server2"; //Set message data message.MessageData = Encoding.UTF8.GetBytes(messageText); //Send message message.Send(); } //Disconnect from DotNetMQ server mdsClient.Disconnect(); }
public MQSendClient() { ServiceName = Utils.MQConfigHelper.MQQualityHelper.ServiceName; IpAddress = Utils.MQConfigHelper.MQQualityHelper.Ip; Port = Utils.MQConfigHelper.MQQualityHelper.Port; client = new MDSClient(ServiceName, IpAddress, Port); }
static void Main(string[] args) { var mdsClient = new MDSClient("StockServer"); mdsClient.MessageReceived += MDSClient_MessageReceived; mdsClient.Connect(); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); mdsClient.Disconnect(); }
static void Main(string[] args) { MDSClient mdsClient = new MDSClient(Utils.MQConfigHelper.MQQualityHelper.ServiceName, Utils.MQConfigHelper.MQQualityHelper.Ip, Utils.MQConfigHelper.MQQualityHelper.Port); mdsClient.MessageReceived += new MessageReceivedHandler(mdsClient_MessageReceived); mdsClient.Connect(); Console.WriteLine("按回车键退出"); Console.ReadLine(); mdsClient.Disconnect(); }
/// <summary> /// Creates a new IncomingDataMessage object from a MDSDataTransferMessage object. /// </summary> /// <param name="client">Reference to the MDSClient object</param> /// <param name="message">MDSDataTransferMessage object to create IncomingDataMessage</param> public IncomingDataMessage(MDSClient client, MDSDataTransferMessage message) { _client = client; DestinationApplicationName = message.DestinationApplicationName; DestinationCommunicatorId = message.DestinationCommunicatorId; DestinationServerName = message.DestinationServerName; MessageData = message.MessageData; MessageId = message.MessageId; PassedServers = message.PassedServers; RepliedMessageId = message.RepliedMessageId; SourceApplicationName = message.SourceApplicationName; SourceCommunicatorId = message.SourceCommunicatorId; SourceServerName = message.SourceServerName; TransmitRule = message.TransmitRule; }
static void Main(string[] args) { //Create MDSClient object to connect to DotNetMQ //Name of this application: Application2 var mdsClient = new MDSClient("Application2"); //Register to MessageReceived event to get messages. mdsClient.MessageReceived += MDSClient_MessageReceived; //Connect to DotNetMQ server mdsClient.Connect(); //Wait user to press enter to terminate application Console.WriteLine("Press enter to exit..."); Console.ReadLine(); //Disconnect from DotNetMQ server mdsClient.Disconnect(); }
static void Main(string[] args) { Console.WriteLine("Press enter to query a stock status"); Console.ReadLine(); //Connect to DotNetMQ var mdsClient = new MDSClient("StockClient"); mdsClient.MessageReceived += mdsClient_MessageReceived; mdsClient.Connect(); //Create a stock request message var stockQueryMessage = new StockQueryMessage { StockCode = "S01" }; //Create a MDS message var requestMessage = mdsClient.CreateMessage(); requestMessage.DestinationApplicationName = "StockServer"; requestMessage.TransmitRule = MessageTransmitRules.NonPersistent; requestMessage.MessageData = GeneralHelper.SerializeObject(stockQueryMessage); //Send message and get response var responseMessage = requestMessage.SendAndGetResponse(); //Get stock query result message from response message var stockResult = (StockQueryResultMessage) GeneralHelper.DeserializeObject(responseMessage.MessageData); //Write stock query result Console.WriteLine("StockCode = " + stockResult.StockCode); Console.WriteLine("ReservedStockCount = " + stockResult.ReservedStockCount); Console.WriteLine("TotalStockCount = " + stockResult.TotalStockCount); //Acknowledge received message responseMessage.Acknowledge(); Console.ReadLine(); //Disconnect from DotNetMQ server. mdsClient.Disconnect(); }
/// <summary> /// Creates a new OutgoingDataMessage object. /// </summary> /// <param name="client">Reference to the MDSClient object</param> public OutgoingDataMessage(MDSClient client) { _client = client; }
public MQSendClient(string serviceName, string ip, int port) { client = new MDSClient(serviceName, ip, port); }