Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the transaction fails, the message is still sent #118

Closed
ajdwfnhaps opened this issue Apr 20, 2018 · 14 comments

Comments

@ajdwfnhaps
Copy link

commented Apr 20, 2018

Hi Savorboard,使用2.2.1版本,遇到一个问题,请教一下。

image

代码逻辑主要是:
1.第一步发送消息
2.第二步处理我的业务逻辑 (ImportBrief方法)
3.提交事务

但是我发现,业务逻辑的方法还没处理完,第一步发送的消息就被消费的订阅方法处理完了。

按我的理解,应该直到事务提交后,才会真正publish消息到MQ,但现在的情况好像不是的,不知道是否我的理解有问题?

PS:
image

@yang-xiaodong yang-xiaodong added the bug label Apr 20, 2018

@yang-xiaodong yang-xiaodong changed the title 本地事务数据一致性的问题 When the transaction fails, the message is still sent Apr 20, 2018

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented May 7, 2018

A more friendly approach is being conceived to implement this feature.

@ajdwfnhaps

This comment has been minimized.

Copy link
Author

commented May 8, 2018

Great,looking forward to the update.

@453495181

This comment has been minimized.

Copy link

commented May 18, 2018

我也遇到了同样的问题,请问修复了吗

@CleanCoder

This comment has been minimized.

Copy link

commented Jun 8, 2018

Here is our solution, before publish the message, check whether it has been committed to the DB. (Note: please do not use dirty read here):

Dispatcher:
`if (_publishedMessageQueue.TryTake(out message, 100, _cts.Token))
{
try
{
bool messgeCommitted = _connection.CommittedMessage(message).GetAwaiter().GetResult();
if (messgeCommitted)
{
_sender.SendAsync(message);
}
else
{
TimeSpan elapsedTime = DateTime.Now - message.LatestPublicStatusCheckTime;
if (elapsedTime < MAX_TIME_OF_WAITING_PUBLISH) // If not time out, re-enqueue the message
{
if (elapsedTime < HALF_SECOND) // current limit control
{
System.Threading.Thread.Sleep(HALF_SECOND);
}

            message.LatestPublicStatusCheckTime = DateTime.Now;
            _publishedMessageQueue.Add(message);
        }
    }
}
catch (Exception ex)
{
    _logger.ExceptionOccuredWhileExecuting(message.Name, ex);
}

}
`

@DiggingSteve

This comment has been minimized.

Copy link

commented Jun 12, 2018

if consuming failed how to roll back

@witskeeper

This comment has been minimized.

Copy link

commented Jul 26, 2018

这个BUG还没修正吗?

@moyuanhui

This comment has been minimized.

Copy link

commented Jul 27, 2018

很多人遇到这个问题,作者还是尽快更新吧!!!

@moyuanhui

This comment has been minimized.

Copy link

commented Jul 27, 2018

@CleanCoder 提供的解决方案并不完整,问题还是存在。。

@wmowm

This comment has been minimized.

Copy link

commented Aug 2, 2018

问题解决了吗,或者是否有更好的解决方案?

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Aug 2, 2018

This is a difficult problem to deal with, we will in version 2.3 to fix this problem, some api break change for this feature support.

The new API call like this :

image

With the new API, everyone can come up with their own ideas!

@yang-xiaodong yang-xiaodong added this to the 2.3.0 milestone Aug 4, 2018

@hzr1348

This comment has been minimized.

Copy link

commented Aug 21, 2018

是不是可以考虑使用TransactionScope来控制事务

@yang-xiaodong

This comment has been minimized.

Copy link
Member

commented Aug 21, 2018

@hzr1348
No, TransactionScope is used to handle two-phase commits. We will solve this problem in version 2.3. You can see the example of the transaction branch to learn about the latest API. We are doing more testing before the release.

@CleanCoder

This comment has been minimized.

Copy link

commented Sep 25, 2018

恕我直言,很多场景是满足不了https://github.com/dotnetcore/CAP/issues/191里面提到的Publish Message须在业务末端调用。

@CleanCoder

This comment has been minimized.

Copy link

commented Sep 25, 2018

@CleanCoder 提供的解决方案并不完整,问题还是存在。。

“方案并不完整”指的是这个方案有未考虑到的场景,还是指提供的代码不完整?
代码是没有全贴上来,但表达的意思都在那了,理解了自己填完整没难度。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.