public void SendMqMessage <TPropery>(MessageType messageType, string strText, List <TPropery> lstProperty) where TPropery : Property { try { IMessage msg; if (messageType.Equals(MessageType.Text)) { msg = producer.CreateTextMessage(); ((ITextMessage)msg).Text = strText; } else { msg = producer.CreateBytesMessage(); ((IBytesMessage)msg).Content = Encoding.Default.GetBytes(strText); } foreach (Property prop in lstProperty) { msg.Properties.SetString(prop.name, prop.value); } producer.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); } catch (System.Exception ex) { } }
public void TestFailoverPassthroughOfCompletedSyncSend() { using (TestAmqpPeer testPeer = new TestAmqpPeer(Address1, User, Password)) { int messagesReceived = 0; testPeer.RegisterMessageProcessor("myQueue", context => { messagesReceived++; context.Complete(); }); testPeer.Open(); NmsConnection connection = EstablishConnection(testPeer); connection.Start(); ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); IQueue queue = session.GetQueue("myQueue"); IMessageProducer producer = session.CreateProducer(queue); //Do a warmup that succeeds producer.Send(producer.CreateTextMessage("first")); producer.Send(producer.CreateTextMessage("second")); Assert.That(() => messagesReceived, Is.EqualTo(2).After(1000, 100)); connection.Close(); } }
public void SendMQMessage(string strText) { ITextMessage msg = producer.CreateTextMessage(); msg.Text = strText; producer.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); }
static void Main(string[] args) { _factory = new ConnectionFactory("tcp://127.0.0.1:61616/"); try { using (_connection = _factory.CreateConnection()) { using (ISession session = _connection.CreateSession()) { IDestination destination = new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("topic"); IMessageProducer producer = session.CreateProducer(destination); Console.WriteLine("Sending: "); _message = producer.CreateTextMessage("Hello ActiveMQ..."); //发送消息 producer.Send(_message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); while (true) { var msg = Console.ReadLine(); _message = producer.CreateTextMessage(msg); producer.Send(_message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.ReadLine(); }
/// <summary> /// 设置发送支持selector进行过滤的消息 /// </summary> /// <param name="content"></param> /// <param name="count"></param> /// <returns></returns> public double SendSelectorMsg(string content, int count) { //定义topic名 CustomData message = new CustomData(); message.desc = content; message.nameCode = 9527; string str = JsonConvert.SerializeObject(message); byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); // IMessage msg = prod.CreateBytesMessage(bytes); TimeSpan ts = new TimeSpan(); DateTime start = DateTime.Now; for (int i = 0; i < count; i++) { IMessage msg = prod.CreateTextMessage(str); msg.Properties.SetString("filter", "demo"); //设置selector msg.Properties.SetDouble("double", 1.11); msg.Properties.SetInt("count", i); msg.Properties.SetInt("sendTime", DateTime.Now.Millisecond); prod.Send(msg, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); } DateTime end = DateTime.Now; ts = end - start; return(ts.TotalSeconds); }
public void Extract(MessageContext message) { try { //发送到MQ队列 if (message == null) { return; } var jsonContent = JsonConvert.SerializeObject(message); if (string.IsNullOrEmpty(jsonContent)) { return; } IMessage activemqMessage = _messageProducer.CreateTextMessage(jsonContent); _messageProducer.Send(activemqMessage); } catch (Exception exception) { _logger.Error(exception); } }
/// <summary> /// Sends the message to processing queue. /// </summary> /// <param name="message">The message.</param> /// <exception cref="System.NotImplementedException"></exception> private void SendMessageToProcessingQueue(string message) { // Create a text message var request = _producer.CreateTextMessage(message); _producer.Send(request); }
/// <summary> /// 发送消息 /// 支持json可序列化,byte[],string类型 /// mqpath:"queue://FOO.BAR",topic://FOO.BAR 示例 /// </summary> public void SendMessage <T>(T obj, string mqpath, Dictionary <string, string> propertydic, ActiveMQMsgDeliveryMode mode = ActiveMQMsgDeliveryMode.Persistent) { var json = ""; if (!(obj is string)) { json = new Serialization.JsonHelper().Serializer(obj); } else { json = obj as string; } IDestination destination = SessionUtil.GetDestination(Session, mqpath); //通过会话创建生产者,方法里面new出来的是MQ中的Queue IMessageProducer prod = Session.CreateProducer(destination); //创建一个发送的消息对象 ITextMessage message = prod.CreateTextMessage(); //给这个对象赋实际的消息 message.Text = json; //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性 if (propertydic != null) { foreach (var map in propertydic) { message.Properties.SetString(map.Key, map.Value); } } //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载 prod.Send(message, (MsgDeliveryMode)mode, MsgPriority.Normal, TimeSpan.MinValue); }
private void button1_Click(object sender, EventArgs e) { try { using (IConnection connection = factory.CreateConnection()) { //Create the Session using (ISession session = connection.CreateSession()) { //Create the Producer for the topic/queue IMessageProducer prod = session.CreateProducer( new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("chat.general")); ITextMessage msg = prod.CreateTextMessage(); msg.Text = this.textBox1.Text; prod.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); this.textBox1.Text = ""; this.textBox1.Focus(); } } } catch (Exception ex) { Console.WriteLine("{0}", ex.Message); } }
internal void SendMensege(string message) { IMessageProducer producer = Session.CreateProducer(Destination); var msg = producer.CreateTextMessage(message); producer.Send(msg); }
public void InitConsumer() { //创建连接工厂 IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); //通过工厂构建连接 IConnection connection = factory.CreateConnection(); //这个是连接的客户端名称标识 connection.ClientId = "firstQueueListener"; //启动连接,监听的话要主动启动连接 connection.Start(); //通过连接创建一个会话 ISession session = connection.CreateSession(); //通过会话创建一个消费者,这里就是Queue这种会话类型的监听参数设置 IMessageConsumer consumer = session.CreateConsumer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue"), "filter1='demo1'"); //注册监听事件 consumer.Listener += new MessageListener(Consumer_Listener); //2. --------------创建生产者 //通过会话创建生产者,方法里面new出来的是MQ中的Queue prod1 = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("returnQueue")); //创建一个发送的消息对象 message = prod1.CreateTextMessage(); message.Properties.SetString("userId", "SC100410"); }
private void btnSend_Click(object sender, EventArgs e) { using (IConnection connection = factory.CreateConnection()) { using (ISession session = connection.CreateSession()) { IMessageProducer prod = session.CreateProducer( //new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("IRAPDCS_MEQ")); new ActiveMQQueue("IRAPTPM_InQueue")); ITextMessage message = prod.CreateTextMessage(); message.Text = edtContent.Text; //string.Format( // content, // edtContent.Text, // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //message.Properties.SetString("filter", edtContent.Text); message.Properties.SetString("filter", "Andon_Test"); message.Properties.SetString("ESBServerAddr", "http://192.168.97.198:16911/RESTFul/SendMQ/"); message.Properties.SetString("ExCode", "IRAPTPM_InQueue"); message.NMSType = "XML"; message.NMSReplyTo = new ActiveMQQueue("IRAPTPM_OutQueue"); prod.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue); MessageBox.Show("发送成功!"); } } }
/// <summary> /// 消息发送(单个) /// </summary> /// <param name="queueName">队列名称</param> /// <param name="entity">消息数据</param> /// <returns>结果(0失败1成功)</returns> public int SendActiveMQMessage(MessageQueueName queueName, MessageEntity entity) { int msgResult = 0; //消息结果 string msgEntity = ""; //文本消息 //判断是否发送消息 if (entity != null) { try { //创建回话 using (ISession sesssion = connection.CreateSession()) { //实体消息序列化文本消息 msgEntity = JsonConvertTool.SerializeObject(entity); //创建生产者 IDestination destination = new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(queueName.ToString()); IMessageProducer producer = sesssion.CreateProducer(destination); //生产消息 ITextMessage _message = producer.CreateTextMessage(msgEntity); //发送消息(持久化) producer.Send(_message, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue); } msgResult = 1; } catch (Exception ex) { // LogHelper.WriteLog(typeof(ActiveMq), "方法名:SendActiveMQMessage发送消息队列异常(单个):", Engineer.maq, entity, ex); } } return(msgResult); }
public void Enqueue(DbConnection connection, DbTransaction transaction, string queue, string jobId) { if (!_client.IsStarted) { _client.Start(); } using (ISession session = _client.CreateSession()) { try { IDestination destination = null; destination = session.GetQueue(queue); IMessageProducer producer = session.CreateProducer(destination); producer.DeliveryMode = MsgDeliveryMode.Persistent; IMessage objMessage = null; objMessage = producer.CreateTextMessage(jobId); producer.Send(objMessage); producer.Close(); } catch (Exception ex) { //_log.Error(ex); } finally { session.Close(); } } }
static void Main(string[] args) { //Create the Connection Factory IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/"); using (IConnection connection = factory.CreateConnection()) { //Create the Session using (ISession session = connection.CreateSession()) { //Create the Producer for the topic/queue IMessageProducer prod = session.CreateProducer( new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("testing")); //Send Messages int i = 0; while (!Console.KeyAvailable) { ITextMessage msg = prod.CreateTextMessage(); msg.Text = i.ToString(); Console.WriteLine("Sending: " + i.ToString()); prod.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); System.Threading.Thread.Sleep(5000); i++; } } } Console.ReadLine(); }
/// <summary> /// 发送消息 /// </summary> public static void Push(string queue, IDictionary <string, string> properties, object messageObj) { try { if (!session.Started) { lock (myLock) { session = ActiveMQConnection.Connection.CreateSession() as Session; session.Start(); } } IMessageProducer producer = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(queue)); ITextMessage message = producer.CreateTextMessage(); message.Text = JsonConvert.SerializeObject(messageObj); foreach (var key in properties.Keys) { message.Properties[key] = properties[key]; } producer.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue); } catch (Exception ex) { } }
/// <summary> /// 添加一条消息到队列中 含有条件key=val /// </summary> /// <param name="config"></param> /// <param name="textMsg"></param> /// <param name="key"></param> /// <param name="val"></param> public static void SendMessageToQuene(AQConfig config, string textMsg, string key, string val) { if (!string.IsNullOrEmpty(textMsg)) { var factory = new ConnectionFactory(config._AQConfigConnectString); //创建连接 using (var connection = factory.CreateConnection()) { //创建一个会话 using (ISession session = connection.CreateSession()) { //通过会话创建生产者,方法里面new出来的是MQ中的Queue IDestination destination = new ActiveMQQueue(config.ActiveMQName); //创建生产者 IMessageProducer producer = session.CreateProducer(destination); //创建一个文本消息 var message = producer.CreateTextMessage(textMsg); //给这个对象赋实际的消息 //message.Text = textMsg; //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性 message.Properties.SetString(key, val); //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位, //当然还有其他重载 //发送消息 producer.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); } } } }
public IActionResult Index() { if (factory == null) { factory = new ConnectionFactory("tcp://localhost:61616"); } //通过工厂建立连接 connection = connection == null ? connection = factory.CreateConnection() : connection; //通过连接创建Session会话 session = session == null ? session = connection.CreateSession() : session; //通过会话创建生产者,方法里面new出来的是MQ中的Queue IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue")); //创建一个发送的消息对象 ITextMessage message = prod.CreateTextMessage(); //给这个对象赋实际的消息 message.Text = Guid.NewGuid().ToString("N"); //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性 message.Properties.SetString("filter", "demo"); message.NMSTimestamp = DateTime.Now.AddDays(1); //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载 prod.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); return(View()); }
/// <summary> /// 发送消息到主题 /// </summary> /// <param name="message">消息内容</param> /// <param name="topicName">主题名</param> /// <param name="bPersistent">是否持久化消息</param> public static void SendTopicMessage(string message, string topicName = null, string filter = null, bool bPersistent = false) { //建立连接 using (IConnection connection = CreateConnection()) { //创建Session会话 using (ISession session = connection.CreateSession()) { if (string.IsNullOrWhiteSpace(topicName)) { topicName = CommonSettings.ActiveMQQueueOrTopic; } //创建MQ的Queue IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic(topicName)); //创建一个发送消息的对象 ITextMessage IMessage = prod.CreateTextMessage(); IMessage.Text = message; //给这个消息对象赋实际的消息 //设置消息对象的过滤关键字属性 if (!string.IsNullOrWhiteSpace(filter)) { IMessage.Properties.SetString("filter", filter); } prod.DeliveryMode = MsgDeliveryMode.NonPersistent; //NonPersistent 非持久化消息 if (bPersistent) { prod.DeliveryMode = MsgDeliveryMode.Persistent; } prod.Priority = MsgPriority.Normal; prod.TimeToLive = TimeSpan.MinValue; prod.Send(IMessage); } } }
public void SendMessage(String cStr) { try { //通过工厂建立连接 using (IConnection vActiveMQ = factory.CreateConnection()) { //通过连接创建Session会话 using (ISession session = vActiveMQ.CreateSession()) { //通过会话创建生产者,方法里面new出来的是MQ中的Queue IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue")); //创建一个发送的消息对象 ITextMessage message = prod.CreateTextMessage(); //给这个对象赋实际的消息 message.Text = cStr; //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性 message.Properties.SetString("filter", "demo"); //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载 prod.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); } } } catch (Exception ex) { log4net.WriteLogFile(ex.Message); } }
static void Main(string[] args) { try { Console.WriteLine("发布者"); IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); using (IConnection connection = factory.CreateConnection()) { using (ISession session = connection.CreateSession()) { IMessageProducer producer = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQTopic("demo")); int i = 0; while (!Console.KeyAvailable) { ITextMessage msg = producer.CreateTextMessage(); msg.Text = i.ToString(); Console.WriteLine($"向Topic发送消息:{i.ToString()}"); producer.Send(msg); Thread.Sleep(2000); i++; } } } } catch (Exception ex) { Console.WriteLine($"发送异常:{ex.Message}"); Console.ReadLine(); } }
public Boolean sendMessage(String messageText) { ISession session = null; try { session = conn.CreateSession(); }catch (Exception e) { return(false); } if (session == null) { return(false); } IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue(queue)); //创建一个发送的消息对象 ITextMessage message = prod.CreateTextMessage(); //给这个对象赋实际的消息 message.Text = messageText; //设置消息对象的属性,这个很重要哦,是Queue的过滤条件,也是P2P消息的唯一指定属性 message.Properties.SetString("filter", "demo"); //生产者把消息发送出去,几个枚举参数MsgDeliveryMode是否长链,MsgPriority消息优先级别,发送最小单位,当然还有其他重载 prod.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); prod.Close(); session.Close(); return(true); }
public void SendMsg(string msg) { ITextMessage message = messageProducer.CreateTextMessage(); message.Text = msg; messageProducer.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); }
static void Main(string[] args) { try { IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/"); using (IConnection connection = factory.CreateConnection()) { using (ISession session = connection.CreateSession()) { IMessageProducer prod = session.CreateProducer( new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("testing")); int i = 0; for (int j = 0; j < 2; j++) { ITextMessage msg = prod.CreateTextMessage(); msg.Text = i.ToString(); msg.Properties.SetString("filter", "zch"); Console.WriteLine("Sending: " + i.ToString()); prod.Send(msg, Apache.NMS.MsgDeliveryMode.NonPersistent, Apache.NMS.MsgPriority.Normal, TimeSpan.MinValue); System.Threading.Thread.Sleep(100); i++; } prod.Close(); session.Close(); } connection.Stop(); connection.Close(); } } catch (System.Exception e) { Console.WriteLine("{0}", e.Message); Console.ReadLine(); } }
public void TestProducerSend() { const int NUM_MSGS = 100; try { using (IConnection connection = GetConnection("c1")) using (IMessageProducer producer = GetProducer("sender")) { connection.ExceptionListener += DefaultExceptionListener; ITextMessage textMessage = producer.CreateTextMessage(); for (int i = 0; i < NUM_MSGS; i++) { textMessage.Text = "msg:" + i; producer.Send(textMessage); } waiter.WaitOne(2000); // wait 2s for message to be received by broker. Assert.IsNull(asyncEx, "Received asynchronous exception. Message : {0}", asyncEx?.Message); } } catch (Exception ex) { this.PrintTestFailureAndAssert(GetTestMethodName(), "Unexpected exception.", ex); } }
public void Requeue() { if (!_client.IsStarted) { _client.Start(); } using (ISession session = _client.CreateSession()) { try { IDestination destination = null; destination = session.GetQueue(_queueName); IMessageProducer producer = session.CreateProducer(destination); producer.DeliveryMode = MsgDeliveryMode.Persistent; IMessage objMessage = null; objMessage = producer.CreateTextMessage(_message.Text); producer.Send(objMessage); producer.Close(); } catch (Exception ex) { //_log.Error(ex); } finally { session.Close(); } } }
private void Send(int numberOfMessages) { IConnectionFactory connectionFactory = new NMSConnectionFactory(NMSTestSupport.ReplaceEnvVar(BrokerUri)); using (IConnection connection = connectionFactory.CreateConnection()) { connection.Start(); using (ISession session = connection.CreateSession()) { IQueue queue = session.GetQueue(Queue); using (IMessageProducer producer = session.CreateProducer(queue)) { producer.DeliveryMode = MsgDeliveryMode.Persistent; ITextMessage message = producer.CreateTextMessage(TextMessage); for (int i = 0; i < numberOfMessages; i++) { producer.Send(message); Tracer.Debug("Sent message."); sent++; } } } } }
public void SendMessage(string ms, string group) { if (!_flag) { return; } //建立工厂连接 using (IConnection connection = factory.CreateConnection()) { //通过工厂连接创建Session会话 using (ISession session = connection.CreateSession()) { //通过会话创建生产者,方法里new出来MQ的Queue IMessageProducer prod = session.CreateProducer(new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue("firstQueue")); //创建一个发送消息的对象 ITextMessage message = prod.CreateTextMessage(); //给这个消息对象赋实际的消息 message.Text = ms; //设置消息对象的属性,是Queue的过滤条件也是P2P的唯一指定属性 message.Properties.SetString("filter", group); prod.Send(message, MsgDeliveryMode.NonPersistent, MsgPriority.Normal, TimeSpan.MinValue); message.Text += "发送成功" + Environment.NewLine; } } }
/// <summary> /// Envia mensaje al ActiveMQ y lo traduce si es requerido. [lanza excepcion] /// </summary> /// <param name="message"></param> /// <param name="queueNameDestino"></param> /// <param name="propertyValue">Valor de la propiedad adicional del objeto ITextMessage (dispositivoId)</param> /// <returns></returns> public async Task EmitirMensajeActiveMQAsync(string message, string queueNameDestino, string propertyValue) { try { CrearConexion(ServidorBrokerUri, AcknowledgementMode.AutoAcknowledge); IDestination destination = SessionUtil.GetDestination(Session, queueNameDestino); using (IMessageProducer producer = Session.CreateProducer(destination)) { ITextMessage textMessage = producer.CreateTextMessage(message); textMessage.Properties.SetString("dispositivoId", propertyValue); producer.Send(textMessage); } } catch (Exception ex) { Log.Error(ex, Constantes.MsgLog.ERRORMETODO, nameof(EmitirMensajeActiveMQAsync)); throw ex; } finally { //if (Connection != null) //{ // Connection.Close(); //} } }
/// <summary> /// Envia un mensaje vacío a la cola especificada. /// </summary> /// <param name="queueName"></param> /// <returns></returns> public void CrearSessionAtomica(string queueName) { try { IConnection connection = CrearSessionAtomica(ServidorBrokerUri, AcknowledgementMode.AutoAcknowledge, UserName, Password, queueName); using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { IDestination destination = SessionUtil.GetDestination(session, queueName); using (IMessageProducer producer = session.CreateProducer(destination)) { ITextMessage textMessage = producer.CreateTextMessage(); producer.DeliveryMode = MsgDeliveryMode.NonPersistent; producer.DisableMessageID = true; producer.DisableMessageTimestamp = true; producer.Send(textMessage); producer.Priority = MsgPriority.Lowest; producer.TimeToLive = TimeSpan.MinValue; producer.Close(); //connection.PurgeTempDestinations(); } } connection.Close(); } catch (Exception ex) { Log.Error(ex, Constantes.MsgLog.ERRORMETODO, nameof(CrearSessionAtomica)); throw ex; } }
public static ITextMessage ToXmlMessage(IMessageProducer producer, object obj) { return SerializeObjToMessage(producer.CreateTextMessage(), obj); }
void Send(IMessageProducer producer, string message) { ITextMessage txtMessage = producer.CreateTextMessage(); txtMessage.Text = message; _logger.DebugFormat("开始向 {0} 发送消息", _nm); try { producer.Send(txtMessage); _logger.DebugFormat("向 {0} 发送消息完成", _nm); } catch (Exception e) { if (_logger.IsDebugEnabled) _logger.Debug(string.Format("向 {0} 发送消息发生错误", _nm), e); throw; } }