BizTalk-从数据库接收端口读取两次 [英] BizTalk - Receive Port reading twice from DB

查看:85
本文介绍了BizTalk-从数据库接收端口读取两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的接收端口是sqlBinding和类型轮询.它调用一个SP来获取一条记录,并根据过滤条件启动相应的业务流程. BizTalk组由2个服务器组成;因此2个ReceiveHostInstances.如果两个主机实例都在运行-有时同一请求被读取两次-导致接收方重复.但是,为什么reeive端口不止一次读取同一条记录?读取更新记录并对其进行更新的proc,以便不会再次感染该记录.

My receive port is of sqlBinding and typed polling. It invokes a SP to fetch a record and based on filter condition the corresponding orchestration kicks off. The BizTalk group consists of 2 servers; thus 2 ReceiveHostInstances. If both the host instances are running -at some point the same request is being read twice - causing a duplicate at the receivers end. But, why is the reeive port reading it the same record more than once? The proc which reads the updates the record and updates it so that it wont be fecthed again.

我在提交10个请求时观察到了这种情况;接收端口读取11次并开始11个业务流程.

I observed this scenario while submitting 10 requests; receive port read 11 times and 11 orchestrations started.

我在一个主机上尝试了相同的请求(10个请求)(如在我的Dev中),接收仅显示10个.有任何线索吗?

I tried the same (10 request) with one host (as in my Dev), the receive is showing 10 only. Any clues?

推荐答案

快速答案是,您有两个选择可以解决此问题:

The quick answer is that you have two options to fix this problem:

  1. 修复存储过程,以便在并发情况下正确运行.
  2. 将您的SQL轮询接收处理程序放置在群集的BizTalk主机中.

下面是对正在发生的情况的解释,在此之下,我提供了解决此问题的实现的详细信息:

Below is an explanation of what is going on, and under that I give details of implementations to fix the issue:

这是由于BizTalk接收位置在多个主机实例上运行时的工作方式(也就是说,在接收位置中指定的适配器的接收处理程序正在具有多个主机实例的主机上运行).

This is due to the way BizTalk receive locations work when running on multiple host instances (that is, that the receive handler for the adapter specified in the receive location is running on a host that has multiple host instances).

在这种情况下,两个主机实例都将运行其接收处理程序.

In this situation both of the host instances will run their receive handler.

这通常不是问题-大多数接收适配器都可以管理此问题,并为您提供预期的行为.例如,文件适配器在读取文件时将其锁定,以防止重复读取.

This is usually not a problem - most of the receive adapters can manage this and give you the behaviour you would expect. For example, the file adapter places a lock on files while they are being read, preventing double reads.

出现问题的主要地方正好是您所看到的-轮询SQL接收位置遇到存储过程时.在这种情况下,BizTalk除了信任SQL过程以给出正确的结果外别无选择.

The main place where this is a problem is exactly what you are seeing - when a polling SQL receive location is hitting a stored procedure. In this case BizTalk has no option other than to trust the SQL procedure to give the correct results.

很难不看程序就很难分辨,但是查询记录的方式并不能保证唯一的读取.

It is hard to tell without seeing your procedure, but the way you are querying your records is not guaranteeing unique reads.

也许您有类似的东西:

Select * From Record 
Where Status = 'Unread'

Update Record 
Set Status = 'Read'
Where Status = 'Unread'

上面的过程可以提供重复的记录,因为在选择和更新之间,选择的另一个调用可以潜入并选择尚未更新的记录.

The above procedure can give duplicate records because between the select and the update, another call of the select is able to sneak in and select the records that have not been updated yet.

该过程的一个简单解决方法是先更新唯一的ID:

One simple fix to the procedure is to update with a unique id first:

Update Record 
Set UpdateId = @@SPID, Status = 'Reading'
Where Status = 'Unread'

Select * From Record
Where UpdateId = @@SPID
And Status = 'Reading'

Update Record
Set Status = 'Read'
Where UpdateId = @@SPID
And Status = 'Reading'

@@ SPID应该是唯一的,但是如果事实并非如此,则可以使用newid()

@@SPID should be unique, but if it proves not to be you could use newid()

在创建新主机时,在BizTalk服务器管理控制台中,可以指定该主机为集群.有关执行此操作的详细信息,请参见Kent Weare的帖子.

Within the BizTalk server admin console when creating a new host it is possible to specify that that host is clustered. Details on doing this are in this post by Kent Weare.

基本上,您将正常创建一个主机,并在每台服务器上创建主机实例,然后右键单击该主机并选择群集.

Essentially you create a host as normal, with host instances on each server, then right click the host and select cluster.

然后,您为在该主机下工作的轮询创建一个SQL接收处理程序,并在您的接收位置使用此处理程序.

You then create a SQL receive handler for the polling that works under that host and use this handler in your receive location.

BizTalk群集主机可确保作为该主机成员的所有项目一次只能在一个主机实例上运行.这将包括您的SQL接收位置,因此在调用过程时,您将没有任何竞争条件的机会.

A BizTalk clustered host ensures that all items that are members of that host will run on one and only one host instance at a time. This will include your SQL receive location, so you will not have any chance of race conditions when calling your procedure.

这篇关于BizTalk-从数据库接收端口读取两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆