private void btn_GoiKham_Click(object sender, EventArgs e) { try { int i = lst_ChoKham.SelectedIndex; ePhieuKham bn = new ePhieuKham(); bn = (ePhieuKham)lst_ChoKham.Items[i]; MessageBox.Show("Đã gọi thành công"); lst_ChoKham.Items.RemoveAt(lst_ChoKham.SelectedIndex); IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); IConnection con = factory.CreateConnection("admin", "admin"); con.Start(); ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge); ActiveMQTopic destination = new ActiveMQTopic("topicKiemTra"); IMessageProducer producer = session.CreateProducer(destination); IMessage msg = new ActiveMQTextMessage(txtMaPhieu.Text.Trim()); producer.Send(msg); session.Close(); con.Close(); } catch (Exception ex) { MessageBox.Show("Lỗi" + ex.Message); } }
protected override ITextMessage DoCreateTextMessage() { ActiveMQTextMessage message = new ActiveMQTextMessage(); message.Connection = this.connection; return(message); }
static void Main(string[] args) { Console.WriteLine("sending message. Enter to exit."); //tạo connection factory IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); //tạo connection IConnection con = factory.CreateConnection("admin", "admin"); con.Start(); //nối tới MOM //tạo session ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge); //tạo producer ActiveMQQueue destination = new ActiveMQQueue("thanthidet"); IMessageProducer producer = session.CreateProducer(destination); //send message //biến đối tượng thành XML document String person p = new person(1001, "Truong Van COi", new DateTime()); //string xml = genXML(p).ToLower(); string xml = new XMLObjects <person>().object2XML(p); Console.WriteLine(xml.ToLower()); IMessage msg = new ActiveMQTextMessage("Hola mondo"); IMessage msg1 = new ActiveMQTextMessage("Halo mondo"); producer.Send(msg); producer.Send(msg1); //shutdown session.Close(); con.Close(); Console.ReadKey(); }
protected virtual void WriteMessage(ActiveMQMessage command, StompFrameStream ss) { ss.WriteCommand(command, "SEND"); ss.WriteHeader("destination", StompHelper.ToStomp(command.Destination)); if (command.ReplyTo != null) { ss.WriteHeader("reply-to", StompHelper.ToStomp(command.ReplyTo)); } if (command.CorrelationId != null) { ss.WriteHeader("correlation-id", command.CorrelationId); } if (command.Expiration != 0) { ss.WriteHeader("expires", command.Expiration); } if (command.Priority != 4) { ss.WriteHeader("priority", command.Priority); } if (command.Type != null) { ss.WriteHeader("type", command.Type); } if (command.TransactionId != null) { ss.WriteHeader("transaction", StompHelper.ToStomp(command.TransactionId)); } ss.WriteHeader("persistent", command.Persistent); // lets force the content to be marshalled command.BeforeMarshall(null); if (command is ActiveMQTextMessage) { ActiveMQTextMessage textMessage = command as ActiveMQTextMessage; ss.Content = encoding.GetBytes(textMessage.Text); } else { ss.Content = command.Content; if (null != command.Content) { ss.ContentLength = command.Content.Length; } else { ss.ContentLength = 0; } } IPrimitiveMap map = command.Properties; foreach (string key in map.Keys) { ss.WriteHeader(key, map[key]); } ss.Flush(); }
private void TruyenData() { IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); IConnection con = factory.CreateConnection("admin", "admin"); con.Start(); ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge); ActiveMQTopic destination = new ActiveMQTopic("PhongKhamNhaKhoa"); IMessageProducer producer = session.CreateProducer(destination); ePhieuKham p = new ePhieuKham(); p.idPhieuKham = idPhieuKham; p.idNV = 1; p.ngayDKKham = DateTime.Today; p.tinhTrang = 1; p.moTa = txtmota.Text.Trim(); p.idKH = Convert.ToInt32(idKhachHang); string xml = new ObjectToXml <ePhieuKham>().object2XML(p); IMessage msg = new ActiveMQTextMessage(xml); producer.Send(msg); session.Close(); con.Close(); }
private void Consumertopic_Listener(IMessage message) { ActiveMQTextMessage text = message as ActiveMQTextMessage; e = new ConvertXML <eBenhNhan>().XML2O(text.Text.ToString()); AddToTreeTopic(e.MSBN); }
public void TtestWriteOnlyBody() { // should always be readable ActiveMQTextMessage textMessage = new ActiveMQTextMessage(); textMessage.ReadOnlyBody = false; try { textMessage.Text = "test"; Assert.IsTrue(textMessage.Text.Length > 0); } catch (MessageNotReadableException) { Assert.Fail("should be readable"); } textMessage.ReadOnlyBody = true; try { Assert.IsTrue(textMessage.Text.Length > 0); textMessage.Text = "test"; Assert.Fail("should throw exception"); } catch (MessageNotReadableException) { Assert.Fail("should be readable"); } catch (MessageNotWriteableException) { } }
public ITextMessage CreateTextMessage(string text) { ActiveMQTextMessage answer = new ActiveMQTextMessage(text); Configure(answer); return(answer); }
private void btnSave_Click(object sender, EventArgs e) { Console.WriteLine("sending message. Enter to exit."); //tạo connection factory IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616"); //tạo connection IConnection con = factory.CreateConnection("admin", "admin"); con.Start(); //nối tới MOM //tạo session ISession session = con.CreateSession(AcknowledgementMode.AutoAcknowledge); //tạo producer ActiveMQQueue destination = new ActiveMQQueue("thanthidet"); IMessageProducer producer = session.CreateProducer(destination); //send message //biến đối tượng thành XML document String patiens p = new patiens(long.Parse(txtMaBN.Text), txtCMND.Text, txtTenBN.Text, txtDiachi.Text); //string xml = genXML(p).ToLower(); string xml = new XMLObjectConverter <patiens>().object2XML(p); Console.WriteLine(xml.ToLower()); IMessage msg = new ActiveMQTextMessage("Hola mondo"); producer.Send(msg); //shutdown session.Close(); con.Close(); }
private Guid?GetClientId(ActiveMQTextMessage message) { if (message.Properties == null || !message.Properties.Contains(MqConsts.ClientId)) { return(null); } return(TypeParse.StrToGuid(message.Properties.GetString(MqConsts.ClientId))); }
private static void Consumer_Listener(IMessage message) { if (message is ActiveMQTextMessage) { ActiveMQTextMessage msg = message as ActiveMQTextMessage; Console.WriteLine("Message: " + msg.Text); } }
// // Write the booleans that this object uses to a BooleanStream // public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) { ActiveMQTextMessage info = (ActiveMQTextMessage)o; int rc = base.TightMarshal1(wireFormat, info, bs); return(rc + 0); }
public void TestNullText() { ActiveMQTextMessage nullMessage = new ActiveMQTextMessage(); SetContent(nullMessage, null); Assert.IsNull(nullMessage.Text); Assert.IsTrue(nullMessage.ToString().Contains("Text = null")); }
public void OneWayFailOnSendMessageTest() { transport.FailOnSendMessage = true; transport.Start(); ActiveMQTextMessage message = new ActiveMQTextMessage(); transport.Oneway(message); }
public void AsyncRequestFailOnSendMessageTest() { transport.FailOnSendMessage = true; transport.Start(); ActiveMQTextMessage message = new ActiveMQTextMessage(); Assert.IsNotNull(transport.AsyncRequest(message)); }
private void Message_Listener(IMessage mess) { if (mess is ActiveMQTextMessage) { ActiveMQTextMessage msg = mess as ActiveMQTextMessage; MessageBox.Show(msg.Text); } }
public void TestSetText() { ActiveMQTextMessage msg = new ActiveMQTextMessage(); string str = "testText"; msg.Text = str; Assert.AreEqual(msg.Text, str); }
private void Consumer_Listener(IMessage message) { if (message is ActiveMQTextMessage) { ActiveMQTextMessage msg = message as ActiveMQTextMessage; ePhieuKham bn = new XmlToObject <ePhieuKham>().XML2object(msg.Text); AddItem(lst_ChoKham, bn); } }
public async System.Threading.Tasks.Task RequestFailOnSendMessageTest() { transport.FailOnSendMessage = true; await transport.StartAsync(); ActiveMQTextMessage message = new ActiveMQTextMessage(); Assert.IsNotNull(await transport.RequestAsync(message)); }
public void OneWaySendMessageTest() { transport.Start(); ActiveMQTextMessage message = new ActiveMQTextMessage(); transport.Oneway(message); Assert.IsTrue(transport.NumSentMessages == 1); Assert.Contains(message, sent); }
private static void Consumer_Listener(IMessage message, TextMessageHandler messageHandler) { if (message is ActiveMQTextMessage && messageHandler != null) { ActiveMQTextMessage actualMessage = (ActiveMQTextMessage)message; messageHandler(actualMessage.Text, message); } }
private void Consumer_Listener(IMessage message) { if (message is ActiveMQTextMessage) { ActiveMQTextMessage msg = message as ActiveMQTextMessage; eDonThuoc dt = new XmlToObject <eDonThuoc>().XML2object(msg.Text); AddItem(lstDsDonThuoc, dt); } }
public void TestShallowCopy() { ActiveMQTextMessage msg = new ActiveMQTextMessage(); string testString = "str"; msg.Text = testString; Message copy = msg.Clone() as Message; Assert.IsTrue(msg.Text == ((ActiveMQTextMessage)copy).Text); }
public void consumer_Listener(IMessage message) { ActiveMQTextMessage m = message as ActiveMQTextMessage; Tracer.DebugFormat("Received Message: {0} delivery count = {1}", m.Text, m.RedeliveryCounter); Assert.AreEqual("1st", m.Text); Assert.AreEqual(receivedCount.Value, m.RedeliveryCounter); receivedCount.GetAndSet(receivedCount.Value + 1); done.countDown(); }
private void ConsumerOnListener(TopicName topicName, IMessage message) { try { ActiveMQTextMessage msg = (ActiveMQTextMessage)message; var clientId = GetClientId(msg); if (clientId == null || clientId == Guid.Empty) { _logger.Error(string.Format("topicName:{0} ConsumerOnListener无效客户端,数据直接抛弃 IP:{1}:{2}", topicName, _configInfo.IpAddress, _configInfo.Port)); return; } var msgType = message.NMSType; NMSMessageType messageType = NMSMessageType.None; if (!string.IsNullOrEmpty(msgType)) { messageType = Utils.GetEnum <NMSMessageType>(msgType); } MqCommandInfo commandInfo = new MqCommandInfo() { StoreId = clientId.Value, Body = msg.Text, Length = msg.Size(), MessageType = messageType, RawNMSType = msgType, NMSMessageId = msg.NMSMessageId, MqInstancId = _configInfo.MqInstanceId, ClientId = this.ClientId, Properties = new Dictionary <string, string>(), }; if (msg.Properties != null) { foreach (var key in msg.Properties.Keys) { if (key == null) { continue; } var keystr = key.ToString(); if (!commandInfo.Properties.ContainsKey(keystr)) { commandInfo.Properties.Add(keystr, msg.Properties.GetString(keystr)); } } } OnTopicDispatch(topicName, commandInfo); if (commandInfo.ExcuteCount == 0) { _logger.Error(string.Format("消息未找到处理程序 类型: {0}大小: {1}", commandInfo.MessageType, commandInfo.Length)); } } catch (Exception ex) { _logger.Error(ex, "主题消费者监听事件处理.ConsumerOnListener"); } }
public void AsyncRequestFailOnSendTwoMessagesTest() { transport.FailOnSendMessage = true; transport.NumSentMessagesBeforeFail = 2; transport.Start(); ActiveMQTextMessage message = new ActiveMQTextMessage(); transport.AsyncRequest(message); transport.AsyncRequest(message); transport.AsyncRequest(message); }
public void RequestMessageTest() { transport.Start(); ActiveMQTextMessage message = new ActiveMQTextMessage(); message.Text = "Hello, World"; transport.Request(message); Assert.IsTrue(transport.NumSentMessages == 1); Assert.IsTrue(sent.Count == 1); Assert.AreEqual(message.Text, (sent[0] as ActiveMQTextMessage).Text); }
public async System.Threading.Tasks.Task RequestFailOnSendTwoMessagesTest() { transport.FailOnSendMessage = true; transport.NumSentMessagesBeforeFail = 2; await transport.StartAsync(); ActiveMQTextMessage message = new ActiveMQTextMessage(); await transport.RequestAsync(message); await transport.RequestAsync(message); await transport.RequestAsync(message); }
public async Task RequestMessageTest() { await transport.StartAsync(); ActiveMQTextMessage message = new ActiveMQTextMessage(); message.Text = "Hello, World"; await transport.RequestAsync(message); Assert.IsTrue(transport.NumSentMessages == 1); Assert.IsTrue(sent.Count == 1); Assert.AreEqual(message.Text, (sent[0] as ActiveMQTextMessage).Text); }
public static void Main(string[] args) { try { Console.WriteLine("About to connect to ActiveMQ"); // START SNIPPET: demo IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616")); using (IConnection connection = factory.CreateConnection()) { Console.WriteLine("Created a connection!"); ISession session = connection.CreateSession(); IDestination destination = session.GetQueue("FOO.BAR"); Console.WriteLine("Using destination: " + destination); // lets create a consumer and producer IMessageConsumer consumer = session.CreateConsumer(destination); IMessageProducer producer = session.CreateProducer(destination); producer.Persistent = true; // lets send a message ITextMessage request = session.CreateTextMessage("Hello World!"); request.NMSCorrelationID = "abc"; request.Properties["NMSXGroupID"] = "cheese"; request.Properties["myHeader"] = "James"; producer.Send(request); // lets consume a message ActiveMQTextMessage message = (ActiveMQTextMessage)consumer.Receive(); if (message == null) { Console.WriteLine("No message received!"); } else { Console.WriteLine("Received message with ID: " + message.NMSMessageId); Console.WriteLine("Received message with text: " + message.Text); } } // END SNIPPET: demo } catch (Exception e) { Console.WriteLine("Caught: " + e); Console.WriteLine("Stack: " + e.StackTrace); } }