WCF& Azure:让辅助角色等待,直到它从另一个辅助角色接收数据

发布于 2024-12-10 22:57:48 字数 929 浏览 1 评论 0原文

我对 WCF 还很陌生。我遵循了有关如何使用内部端点 (WCF) 进行角色到角色通信的教程。 教程链接

他们实际上创建了多个辅助角色实例并互相戳戳。

代码是

            foreach (var ep in endPoints)
        {
            IService1 worker = WorkerRole.factory.CreateChannel(new EndpointAddress(string.Format("net.tcp://{0}/Service1", ep.IPEndpoint)));

            try
            {
                Trace.WriteLine(worker.SayHello(currentInstance.Id.ToString()), "Information");
                ((ICommunicationObject)worker).Close();
            }
            catch (Exception e)
            {
                Trace.TraceError("unable to poke worker role instance '{0}'. {1}", ep.RoleInstance.Id, e.Message);
                ((ICommunicationObject)worker).Abort();
            }
        }

但我想让一个工作角色等到它被其他工作角色戳到。举例来说,有 3 个工作者角色。工作角色 2 和工作角色 3 应该等到它被工作角色 1 戳到。

谁能告诉我该怎么做。

I am quite new to WCF. I followed a tutorial on how to use Internal Endpoints (WCF) to make a Role to Role communication. Link for the tutorial

They actually create multiple instance of a worker role and poke each other.

The code is

            foreach (var ep in endPoints)
        {
            IService1 worker = WorkerRole.factory.CreateChannel(new EndpointAddress(string.Format("net.tcp://{0}/Service1", ep.IPEndpoint)));

            try
            {
                Trace.WriteLine(worker.SayHello(currentInstance.Id.ToString()), "Information");
                ((ICommunicationObject)worker).Close();
            }
            catch (Exception e)
            {
                Trace.TraceError("unable to poke worker role instance '{0}'. {1}", ep.RoleInstance.Id, e.Message);
                ((ICommunicationObject)worker).Abort();
            }
        }

But I want to make a worker role wait till it is being poked by other worker role. Say for example, there are 3 worker roles. The worker role 2 and worker role 3 should wait till it is being poked by worker role 1.

Can anyone tell me how to do that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌梦深 2024-12-17 22:57:48

我想我的架构会略有不同。

使用队列可能会更简洁,而不是让辅助角色公开 WCF 端点并在它们之间发送消息。

消息可以发布到队列并由其他辅助角色拾取和处理。这引入了一定程度的持久性,因为如果应该接收消息的辅助角色由于任何原因而关闭,它可以在恢复时继续处理其队列上的这些消息。此外,处理消息时发生的任何未处理的异常都意味着该消息在一定的超时时间后会重新出现在队列中。如果您的应用程序/网站确实取得了成功,您可以添加这些辅助角色的其他实例,以更快地处理队列上的消息。

因此,通过使用队列,您可以获得一定程度的额外耐用性,并且以后更容易扩展。

有一个关于使用队列的很好的介绍 开发者融合网站

I think I would architect this slightly differently.

Instead of having worker roles exposing WCF Endpoints and sending messages between them it may be neater to use queues.

Messages can be posted to queues and picked up and processed by other worker roles. This introduces a certain amount of durability in that if a worker role that is supposed to receive a message is down for any reason it can carry on processing those messages on its queue when it comes back up. Also any unhandled exceptions that happen whilst processing a message will mean that the message reappears on the queue after a certain timeout period. If your app/site really takes off you can add additional instances of those worker roles to process the messages on the queues more quickly.

Therefore by using queues you have a certain amount of additional durability and its easier to scale up later.

There is a good intro to using queues on the developer fusion website

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文