using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Apache.NMS;
using Apache.NMS.ActiveMQ;
using Apache.NMS.ActiveMQ.Commands;
using Apache.NMS.Util;
using System.Threading;
namespace ActiveMqDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("按回车开始!");
Console.ReadLine();
IConnectionFactory factory =new ConnectionFactory("tcp://localhost:61616");
using (IConnection conn = factory.CreateConnection("wu", "123456"))
{
using (ISession session = conn.CreateSession())
{
ActiveMQTopic topic = new ActiveMQTopic("test");
using (IMessageProducer producer = session.CreateProducer(topic))
{
conn.Start();
//可以写入字符串,也可以是一个xml字符串等
for (int i = 0; i < 10; i++)
{
ITextMessage message = session.CreateTextMessage("新messsage" + i);
producer.Send(message,MsgDeliveryMode.NonPersistent,MsgPriority.Normal,TimeSpan.MinValue);
Console.WriteLine("发送新消息:" + i);
Thread.Sleep(1000);
}
}
}
}
Console.ReadKey();
}
}
}