Alright, so I’m about 90% sure that this isn’t possible, but I thought I’d ask anyway. Maybe I’m missing something.
I’m trying to use WCF over MSMQ with transacted batching. Long story short, I have a queue with possibly even 200-300k messages in it at a time and I need to put them in a database. They ultimately go through Service Broker but only after I do some preprocessing in the MSMQ client.
The idea is to get as many messages as possible (and supported by my infrastructure) at once, pre-process them and then send them in a table variable to SQL Server, where they ultimately go in a Service Broker queue.
With transacted batching I am indeed given N (100, 1000, etc) messages per transaction, but they all come in my WCF client sequentially. So the service operation is called N times, once for each message. The transaction is committed or rolled back by the framework after the operation returns for the last message .
My idea was that it would be more efficient to get them all in a collection and start processing right away the entire collection and also send it to the database.
Doing some kind of trick (like storing them in a static something and once I hit N start processing) is not very nice and I’m trying to avoid.
I don’t have any code to post, because I didn’t write it yet. I’ve done transacted batching before and I tend to believe that this is not possible.
Ultimately I will drop my WCF client and Receive() the hell out of it inside a MessageQueueTransaction, wrapped of course in a distributed transaction (down to SQL Server).
But, do you know of any supported way through which I could get a list and not fiddle with the default distributed transaction created by WCF and also avoid holding anything in static collections?
Thanks!
I do not think it is possible either. If you worked with MSMQ directly you’d see you can only get messages one by one.
Having said that there is a significant difference between WCF (over MSMQ) and MSMQ. First one is push based while the latter is pull based. If you can switch to direct MSMQ it would be easy to pull
Nmessages out of it and process/save in a batch. Programming against MSMQ is much easier than WCF.