473,785 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Message Queue and Distributed transactions

Hi.

The problem is a bit hard to explain.
I have a ServicedCompone nt method which runs a distributed transaction
consisting on a a MessageQueue reception and several database operations.
That ServicedCompone nt method is called from a pool of threads which get
blocked in the Receive method of the queue. At that moment there are as many
open transactions in the DTC as the number of threads in the pool. After 60
seconds of inactivity the transactions get cancelled by the DTC and the
threads get unblocked and everything starts again. My question is, how can I
achieve that a thread calls the ServicedCompone nt method (and thus starts a
new transaction) only when there is a message on the queue to be received?.

The problem is I get a lot of cancelled transactions because of timeouts of
the DTC, as I need a distributed transaction i cannot use the BeginReceive
method. If I use the BeginPeek method and instance the ServicedCompone nt on
the PeekCompleted, all the threads get unblocked and the same problem arises
again. Can anybody help me?

this is my code:

class Worker {
private int threadId;

public Worker (int threadId) {
this.threadId=t hreadId;
}

//doWork is the ThreadStart method
public void doWork() {
//ShippingProcess .endShippingPro cess is a static bool field
while (!ShippingProce ss.endShippingP rocess) {
try {
using (MessageHandler mh = new MessageHandler( )) {
mh.handleMessag e();
}
}
catch (Exception e) {
//Write EventLogEntry
}
}
}
}

[Transaction(Tra nsactionOption. Required)]
public class MessageHandler : ServicedCompone nt {
public MessageHandler( ) {
}

[AutoComplete()]
public void handleMessage() {
SHQM shippingMessage ;
STQM stockMessage;

using (MessageQueue queue = new MessageQueue(SH IPPING_QUEUE_ST RING)) {
try {
Type[] shipMessageType = {typeof(SHQM)};
queue.Formatter = new XmlMessageForma tter(shipMessag eType);
//ALL THE THREADS GET BLOCKED HERE
shippingMessage =
(SHQM)queue.Rec eive(MessageQue ueTransactionTy pe.Automatic).B ody;
}
catch (MessageQueueEx ception e) {
//Write EventLog
throw;
}
catch (Exception e) {
//Write EventLog
throw;
}
}
//DB operatios go here
}
}
}
Regards, Rodrigo.
Nov 3 '05 #1
2 2625
Hi Rodrigo,

You can use:

try
{
queue.Receive(T imeSpan.Zero, MessageQueueTra nsactionType.Au tomatic);
}
catch(MessageQu eueException e)
{
if( e.MessageQueueE rrorCode.IOTime out )
{
//Do what ever you want when there is no message in the queue.
}
}

Regards,

Dinh Duy Tran
[MCSD/CSDP]

"Rodrigo GarcÃ*a" wrote:
Hi.

The problem is a bit hard to explain.
I have a ServicedCompone nt method which runs a distributed transaction
consisting on a a MessageQueue reception and several database operations.
That ServicedCompone nt method is called from a pool of threads which get
blocked in the Receive method of the queue. At that moment there are as many
open transactions in the DTC as the number of threads in the pool. After 60
seconds of inactivity the transactions get cancelled by the DTC and the
threads get unblocked and everything starts again. My question is, how can I
achieve that a thread calls the ServicedCompone nt method (and thus starts a
new transaction) only when there is a message on the queue to be received?.

The problem is I get a lot of cancelled transactions because of timeouts of
the DTC, as I need a distributed transaction i cannot use the BeginReceive
method. If I use the BeginPeek method and instance the ServicedCompone nt on
the PeekCompleted, all the threads get unblocked and the same problem arises
again. Can anybody help me?

this is my code:

class Worker {
private int threadId;

public Worker (int threadId) {
this.threadId=t hreadId;
}

//doWork is the ThreadStart method
public void doWork() {
//ShippingProcess .endShippingPro cess is a static bool field
while (!ShippingProce ss.endShippingP rocess) {
try {
using (MessageHandler mh = new MessageHandler( )) {
mh.handleMessag e();
}
}
catch (Exception e) {
//Write EventLogEntry
}
}
}
}

[Transaction(Tra nsactionOption. Required)]
public class MessageHandler : ServicedCompone nt {
public MessageHandler( ) {
}

[AutoComplete()]
public void handleMessage() {
SHQM shippingMessage ;
STQM stockMessage;

using (MessageQueue queue = new MessageQueue(SH IPPING_QUEUE_ST RING)) {
try {
Type[] shipMessageType = {typeof(SHQM)};
queue.Formatter = new XmlMessageForma tter(shipMessag eType);
//ALL THE THREADS GET BLOCKED HERE
shippingMessage =
(SHQM)queue.Rec eive(MessageQue ueTransactionTy pe.Automatic).B ody;
}
catch (MessageQueueEx ception e) {
//Write EventLog
throw;
}
catch (Exception e) {
//Write EventLog
throw;
}
}
//DB operatios go here
}
}
}
Regards, Rodrigo.

Nov 3 '05 #2
Thanks for your advice.

If I do what you say, there will be more cancelled transactions.
The threads shouldn't create an instance of 'Distributed' if there aren't
messages on the queue. If you put a timeout of zero seconds, the threads will
be creating and destroying transactions if there aren't messages on the queue.

I tried with a BeginPeek call on the threads, but it didn't work as expected.

The goal is to get the threads blocked until there is a message but without
calling Receive or BeginReceive

Any more ideas would be helpful.
Nov 5 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8219
by: Eirik Tryggeseth | last post by:
During deployment of an application using distributed transactions managed under COM+ on an Oracle 9i RAC database, we encounter situations where the load balancing mechanisms in the RAC result in that the component context in the distributed transaction (in our case two different COM components) cannot hold onto the same ODBC connection. Or it may be that the database session is changed dynamically for the ODBC connection, so that...
7
2382
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server or Oracle) controlled by Microsoft's Distributed Transaction Coordinator in a Windows2000 environment, with any resource manager under the control of DECdtm (e.g. Rdb (or Oracle via the XA Veneer)) in a VMS environment.
0
2465
by: DotNetJunkies User | last post by:
I am writing a distributed transaction code. My current scenario include a client database(Suppose client- having 4 main database) which can be installed anywhere which would connect to a public database placed at ISP datacentre(Suppose Server- having 2 database). this server database is added to client as linked server through vb.net interface. i have a transmission routine which transmitts the data from the client to Server and update client...
2
2931
by: Jo Siffert | last post by:
Hi all, I would like to perform an INSERT INTO LINKEDSVR.dbo.xyz.abc SELECT ... FROM dbo.dfg where LINKEDSVR is a linked server on another machine. Both servers are running SQLServer 2000 and have the DTC running. When I run this batch from QueryAnalyzer without explicitly using
8
4371
by: Don Riesbeck Jr. | last post by:
I have an C# EnterpriseService component that is part of an application I am developing that is responsible for writing data to an SQL Server. (it reads from a local DB (MSDE), then writes to a 'remote' DB (SQL Server 2k)...) On some machines I get the following exception: System.InvalidOperationException: An error occurred while enlisting in a distributed transaction. at...
2
304
by: Rodrigo García | last post by:
Hi. The problem is a bit hard to explain. I have a ServicedComponent method which runs a distributed transaction consisting on a a MessageQueue reception and several database operations. That ServicedComponent method is called from a pool of threads which get blocked in the Receive method of the queue. At that moment there are as many open transactions in the DTC as the number of threads in the pool. After 60 seconds of inactivity the...
2
2797
by: Dan Kelley | last post by:
I have 2 services, ServiceA and ServiceB. Certain user driven functions require ServiceA to perform some DB tasks, before sending a request to ServiceB to perform some additional tasks. If ServiceB fails to execute the request, I would like ServiceA to rollback its changes. ServiceA and ServiceB are located on 2 different servers on the same network. I am struggling to find resources that cover this scenario. most articles that discuss...
9
1753
by: Paul Rubin | last post by:
Does anyone have an implementation of a distributed queue? I.e. I have a long running computation f(x) and I'd like to be able to evaluate it (for different values of x) on a bunch of different computers simultaneously, the usual "worker thread" pattern except distributed across a network. I guess this is pretty easy to write with a centralized socket listener that dispatches requests through a Queue to multiple threads on the same...
3
3110
by: BLUE | last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL? Thanks, Luigi.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.