// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using Apache.NMS; using Apache.NMS.ActiveMQ; namespace PubAMQ { public class Program { private const string SERVER = "tcp://localhost:61616"; private const string UN = "arne"; private const string PW = "topsecret"; private const string TNAME = "TestT"; private const string PAYLOAD = "\r\n 123\r\n ABC\r\n"; public static void Main(string[] args) { IConnectionFactory confac = new ConnectionFactory(new Uri(SERVER)); using(IConnection con = confac.CreateConnection(UN, PW)) { con.Start(); using(ISession ses = con.CreateSession(AcknowledgementMode.AutoAcknowledge)) { using(ITopic t = ses.GetTopic(TNAME)) { using(IMessageProducer publisher = ses.CreateProducer(t)) { for(int i = 0; i < 3; i++) { IMessage smsg = ses.CreateTextMessage(PAYLOAD); publisher.Send(smsg); } } } } } } } }