| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using CoreFS.CA06;
- using Core.Sip.Amq.client;
- using Core.Sip.Amq.transport;
- namespace Core.LZMes.Client.UIL.UIL02
- {
- public partial class UIL020010 : FrmBase, IMessageListener
- {
- // 连接消息系统
- Core.Sip.Amq.client.Client _connection;
- IClientSession _session;
- RangeSet _range;
- public UIL020010()
- {
- InitializeComponent();
- string host = "localhost";
- int port = 5672;
- string virtualhost = "test";
- string username = "guest";
- string password = "guest";
- _range = new RangeSet();
- _connection = new Core.Sip.Amq.client.Client();
- try
- {
- _connection.Connect(host, port, virtualhost, username, password);
- _session = _connection.CreateSession(50000);
- // 队列声明
-
- }
- catch (Exception e)
- {
- MessageBox.Show("连接错误:" + e.Message);
- }
- }
- private void initAmq()
- {
- _session.QueueDeclare("MQ_SIP_AMF", Option.EXCLUSIVE, Option.AUTO_DELETE);
- _session.ExchangeBind("MQ_SIP_AMF", "amq.direct", "RK_SIP_MQ");
- _session.AttachMessageListener(this, "MQ_SIP_AMF");
- }
- // 消息接收接口
- public void MessageTransfer(IMessage m)
- {
- BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
- byte[] body = new byte[m.Body.Length - m.Body.Position];
- reader.Read(body, 0, body.Length);
- ASCIIEncoding enc = new ASCIIEncoding();
- string message = enc.GetString(body);
- Console.WriteLine("Message: " + message);
- string routingKey = m.DeliveryProperties.GetRoutingKey();
-
- // Add this message to the list of message to be acknowledged
- _range.Add(m.Id);
- if (message.Equals("That's all, folks!"))
- {
- // Acknowledge all the received messages
- _session.MessageAccept(_range);
- lock (_session)
- {
- Monitor.Pulse(_session);
- }
- }
- }
- private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
- {
- }
- }
- }
|