Example #1
0
        /// <summary>
        /// 发送普通消息
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="content">内容</param>
        /// <param name="bizFunc">业务方法</param>
        /// <param name="tag">消息标签</param>
        /// <param name="key">消息Key</param>
        /// <returns></returns>
        public string SendMessage(string topic, string content, Func <Message, bool> bizFunc, string tag = "", string key = "")
        {
            var message = ComposeMessage(topic, content, tag, key);

            var result = producer.send(message, new ExtendedLocalTransactionExecuter(bizFunc));

            return(result.getMessageId());
        }
Example #2
0
        /// <summary>
        /// 代理TransactionProducer实例的send方法
        /// </summary>
        /// <param name="message">Message实例</param>
        /// <param name="parameter">parameter参数</param>
        /// <returns>SendResultONS实例</returns>
        public SendResultONS send(Message message, object parameter)
        {
            SendResultONS sendResultONS = null;

            if (_producer != null)
            {
                ONSLocalTransactionExecuter executer = parameter as ONSLocalTransactionExecuter;
                sendResultONS = _producer.send(message, executer);
            }
            return(sendResultONS);
        }
Example #3
0
 public void SendTransactionMessage(string tag, string byteBody, string shardingKey)
 {
     try
     {
         Message msg = new Message(factoryInfo.getPublishTopics(), tag, byteBody);
         msg.setKey(shardingKey);
         LocalTransactionExecuter myExecuter = new MyLocalTransactionExecuter();
         //事务检查
         myChecker.check(msg);
         SendResultONS sendResult = transactionProducer.send(msg, myExecuter);
         //事务执行
         myExecuter.execute(msg);
     }
     catch (Exception ex)
     {
         Console.WriteLine("\nexception of sendmsg:{0}");
     }
 }
Example #4
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            Form1.ActiveForm.FormClosing += ActiveForm_FormClosing;

            /*
             * Message msg = new Message(
             * //Message Topic
             *  factoryInfo.getPublishTopics(),
             *  //Message Tag
             *  "TagA",
             *  //Message Body
             *  factoryInfo.getMessageContent()
             * );
             * //*/

            Message msg = new Message(
                //Message Topic
                factoryInfo.getPublishTopics(),
                //Message Tag
                "TagA",
                //Message Body
                messageTextBox.Text.Trim()
                );

            // 设置代表消息的业务关键属性,请尽可能全局唯一
            // 以方便您在无法正常收到消息情况下,可通过 MQ 控制台查询消息并补发。
            // 注意:不设置也不会影响消息正常收发
            //msg.setKey("ORDERID_100");

            // 发送消息,只要不抛出异常,就代表发送成功
            try
            {
                LocalTransactionExecuter myExecuter = new MyLocalTransactionExecuter();
                SendResultONS            sendResult = producer.send(msg, myExecuter);
            }
            catch (Exception exception)
            {
                Console.WriteLine("\nexception of sendmsg:{0}", exception.ToString());
            }
        }