Is NServiceBus (AsA_Server) possible without DTC?

I am using NServiceBus for the first time and have a small simple application in which the user submits the form, the form fields are then sent to the queue, and the handler collects this data and writes it to the database using linq-to-SQL.

Any changes to the component services are a complete lack-of-relation with respect to the database administrator, so now I am looking for an alternative to DTC (which is not enabled on the database server), but using AsA_Server so that messages are not cleared.

I tried to remove AsA_Server after IConfigureThisEndpoint and specify the configuration myself, but this does not work (the console appears, the page loads, but nothing happens, it does not even stop at the control points.) AsA_Client really works, but as I understand it, the messages will be cleared at startup which I need to avoid.

Any suggestions?

Thanks,

OMK

EDIT: this has now been resolved by wrapping a call to the database in the transaction caliper area, which allows you to work with the database without any external transactions to record:

using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Suppress)) { // code here sc.Complete(); } 
+6
source share
4 answers

When you use AsA_Server, you indicate that you want long queues, and you will need to configure transactional queues.

When sending / receiving transactionally, MSMQ needs to be sent, transferred, received, and processed as part of a single transaction. However, in fact, all of these steps occur in their own transactions.

For example, a send transaction ends when the sender sends a message to his local MSMQ subsystem (even if the queue address is deleted, the sender still sends to the local queue, which acts as a kind of proxy for the remote queue).

Transmission is complete when the MSMQ subsystem on the sender machine successfully transmits a message to the MSMQ subsystem on the recipient machine.

Even if this can happen on one machine, I assume that your Handle () method writes to the database on another machine.

The problem is that for a transaction to succeed in terms of a transaction, your call to the database must be successful. Only after that the message will be disconnected from the input queue. This prevents the accidental loss of a message during processing failure.

However, in order to ensure that this function is performed over the network, you need to use DTC to coordinate the distributed transaction with the database.

Bottom line, if you want long queues in a distributed environment, then you will need to use MSDTC.

Hope this helps.

+9
source

There is an alternative. In your connection string, you can add an option so as not to be credited to a distributed transaction, and this will result in your database connection being ignored in the DTC.

Of course, if this is specified in config, all database transactions for the application are ignored by DTC, and not just specific.

Example:

 <add key="DatabaseConnectionString" value="Data Source=SERVERNAME;Initial Catalog=DBNAME;Integrated Security=True;Enlist=False"/> 
+7
source

With NServiceBus 4.0, you can do the following, which finally helped me:

  Configure.Transactions.Advanced(t => { t.DisableDistributedTransactions(); t.DoNotWrapHandlersExecutionInATransactionScope(); }); 
+6
source

When you use As interfaces (AsA_Client, AsA_Server), the configuration is applied after Init (), so all the settings that you make regarding MsmqTransport and UnicastBus are overridden.

You can override these settings with IWantTheConfiguration in the IHandleProfile implementation. You get the configuration after applying the default roles, but before starting the bus.

Thus, you can change the default profile settings and adapt them to your needs: deactivate transactions, enable impersonation ...

Example:

 public class DeactivateTransactions : IHandleProfile<Lite>, IWantTheEndpointConfig { private IConfigureThisEndpoint configure; public IConfigureThisEndpoint Config { get { return configure; } set { this.configure = value; Configure.Instance.MsmqTransport() .PurgeOnStartup(false) .IsTransactional(false); // Or other changes } } public void ProfileActivated() { } } 
+5
source

Source: https://habr.com/ru/post/893071/


All Articles