my understanding is that when specifying AcknowledgementMode.ClientAcknowledge in the producer, i should be able to stop and restart the consumer and the broker will resend all the unacknowledged messages on the topic. i can't get this to work however. (i've also tried using an onMessage listener in the consumer but i get the same behavior.) any assistance is appreciated. here's my producer:
static void Main(string[] args) {
IConnectionFactory factory = new NMSConnectionFactory("tcp://localhost:61616");
using (IConnection connection = factory.CreateConnection()) {
connection.ClientId = "producer";
using (ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge)) {
IDestination destination = SessionUtil.GetDestination(session, "MY_TOPIC", DestinationType.Topic);
IMessageProducer producer = session.CreateProducer(destination);
while (!Console.KeyAvailable) {
string message = "[" + DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss.fff") + "]";
ITextMessage xtext_message = session.CreateTextMessage(message);
producer.Send(xtext_message, MsgDeliveryMode.Persistent, MsgPriority.Normal, new TimeSpan(1, 0, 0));
Console.WriteLine("Sent message:" + message);
Thread.Sleep(1000);
}
}
}
}
here's my consumer:
static void Main(string[] args) {
IConnectionFactory factory = new NMSConnectionFactory("tcp://localhost:61616/");
using (IConnection connection = factory.CreateConnection()) {
connection.ClientId = "consumer";
connection.Start();
using (ISession session = connection.CreateSession()) {
IMessageConsumer consumer = session.CreateConsumer(SessionUtil.GetDestination(session, "MY_TOPIC", DestinationType.Topic));
while (!Console.KeyAvailable) {
ITextMessage receivedMsg = consumer.Receive() as ITextMessage;
if (receivedMsg != null) {
Console.WriteLine("--> received: " + receivedMsg.Text);
}
}
}
}
}