Is there a way to configure Acknowledgements with Spring.NET?
In code it looks like this:
var msgQ = new MessageQueue(OrdersQueueName)
{
DefaultPropertiesToSend =
{
AcknowledgeType = AcknowledgeTypes.FullReachQueue |
AcknowledgeTypes.FullReceive,
AdministrationQueue = new MessageQueue(AckQueueName)
}
};
Could it be done with the ProductTemplate
? Another way?
For me, this configuration worked:
<objects xmlns="http://www.springframework.net">
<!-- for http://stackoverflow.com/questions/3491152/configuring-acknowledgements-with-spring-net -->
<object name="orders" type="q3491152.MessageQueue, q3491152">
<property name="Name" value="orders-from-xml" />
<property name="DefaultPropertiesToSend">
<object type="q3491152.PropertiesToSend, q3491152">
<property name="AdministrationQueue" ref="anotherQ" />
<property name="AcknowledgeType"
expression="T(q3491152.AcknowledgeTypes).FullReachQueue or T(q3491152.AcknowledgeTypes).FullReceive" />
</object>
</property>
</object>
<object name="anotherQ" type="q3491152.MessageQueue, q3491152">
<property name="Name" value="anotherQ" />
</object>
</objects>
In this example I mocked the (apparently) relevant parts of the msmq classes. I use an expression to get a bit-wise comparison on the enum.
If you register the AcknowledgeType
with the Spring.Core.TypeResolution.TypeRegistry
using TypeRegistry.RegisterType("AcknowledgeTypes", typeof(AcknowledgeTypes));
, the expression further simplifies to:
<property name="AcknowledgeType"
expression="AcknowledgeTypes.FullReachQueue or AcknowledgeTypes.FullReceive" />
I've tested it with the following program, against Spring.NET 1.3.1:
using System;
using Spring.Context;
using Spring.Context.Support;
namespace q3491152
{
internal class Program
{
private static void Main(string[] args)
{
IApplicationContext ctx = new XmlApplicationContext("objects.xml");
var qFromCode = new MessageQueue
{
Name="orders-from-code",
DefaultPropertiesToSend =
{
AcknowledgeType = AcknowledgeTypes.FullReachQueue |
AcknowledgeTypes.FullReceive,
AdministrationQueue = new MessageQueue()
}
};
var qFromXml = (MessageQueue) ctx.GetObject("orders");
PrintQ(qFromCode);
PrintQ(qFromXml);
Console.ReadLine();
}
private static void PrintQ(MessageQueue q)
{
Console.WriteLine("Q: {0}; AcknowledgeType: {1}", q.Name, q.DefaultPropertiesToSend.AcknowledgeType);
}
}
public class MessageQueue
{
public MessageQueue()
{
DefaultPropertiesToSend = new PropertiesToSend();
}
public string Name { get; set; }
public PropertiesToSend DefaultPropertiesToSend { get; set; }
}
public class PropertiesToSend
{
public AcknowledgeTypes AcknowledgeType { get; set; }
public MessageQueue AdministrationQueue { get; set; }
}
[Flags]
public enum AcknowledgeTypes
{
None = 0,
FullReachQueue,
FullReceive
}
}
Which outputs:
Q: orders-from-code; AcknowledgeType: FullReachQueue, FullReceive
Q: orders-from-xml; AcknowledgeType: FullReachQueue, FullReceive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With