Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rebus saga中请求/回复的自相关_Rebus_Saga - Fatal编程技术网

Rebus saga中请求/回复的自相关

Rebus saga中请求/回复的自相关,rebus,saga,Rebus,Saga,我想问的是,我是否正确理解,在我执行saga for Request/Reply时,我可以将配置如何查找saga留空 如果这是真的,那么最好在Wiki页面中提及它,以及在adapter中注册saga的必要性:) 下面的代码似乎有效,你能看看它是否正常吗 namespace ConsoleApplication1 { class Program { static IBus bus; static void Main(string[] args)

我想问的是,我是否正确理解,在我执行saga for Request/Reply时,我可以将
配置如何查找saga
留空

如果这是真的,那么最好在Wiki页面中提及它,以及在adapter中注册saga的必要性:)

下面的代码似乎有效,你能看看它是否正常吗

namespace ConsoleApplication1
{
    class Program
    {
        static IBus bus;
        static void Main(string[] args)
        {
            var adapter = new BuiltinContainerAdapter();

            adapter.Register<SampleSaga>(() => new SampleSaga(bus));

            bus = Configure.With(adapter)
                             .Logging(l => l.ColoredConsole())
                             .Transport(t => t.UseMsmq("enpoint1", "endpoint1_errors"))
                             .MessageOwnership(x => x.FromRebusConfigurationSection())
                             .Sagas(x => x.StoreInMemory())
                             .CreateBus()
                             .Start();

            bus.SendLocal(new SampleMessage() { Test = "Hi there" });
        }
    }

    class SampleSaga : Saga<MessageHolder<SampleMessage>>,
                                           IAmInitiatedBy<SampleMessage>,
                                           IHandleMessages<Response>
    {
        IBus bus;

        public SampleSaga(IBus bus)
        {
            this.bus = bus;
        }

        public override void ConfigureHowToFindSaga()
        {
        }

        public void Handle(SampleMessage message)
        {
            Data.Message = message;
            bus.Send(new Request());
        }

        public void Handle(Response message)
        {
            Console.Write(string.Format("Response arrived. Holded message: {0}", Data.Message.Test));
            MarkAsComplete();
        }
    }

    class MessageHolder<T> : ISagaData
    {
        public Guid Id { get; set; }
        public int Revision { get; set; }
        public T Message { get; set; }
    }

    class SampleMessage
    {
        public string Test { get; set; }
    }
}


namespace ConsoleApplication2
{
    class Program
    {
        static IBus bus;
        static void Main(string[] args)
        {
            var adapter = new BuiltinContainerAdapter();

            adapter.Handle<Request>(x => bus.Reply(new Response()));

            bus = Configure.With(adapter)
                             .Logging(l => l.ColoredConsole())
                             .Transport(t => t.UseMsmq("endpoint2", "endpoint2_errors"))
                             .MessageOwnership(x => x.FromRebusConfigurationSection())
                             .CreateBus()
                             .Start();
        }
    }

    public class Request
    {

    }

    public class Response
    {

    }
}
命名空间控制台应用程序1
{
班级计划
{
静态IBus总线;
静态void Main(字符串[]参数)
{
var适配器=新的内置容器适配器();
适配器寄存器(()=>newsampleSAGA(总线));
总线=配置。带(适配器)
.Logging(l=>l.ColoredConsole())
.Transport(t=>t.usemmq(“enpoint1”、“endpoint1\u错误”))
.MessageOwnership(x=>x.fromReBusConfiguration节())
.Sagas(x=>x.StoreInMemory())
.CreateBus()
.Start();
SendLocal(new SampleMessage(){Test=“Hi there”});
}
}
阶级样本:传奇,
我是由,
IHandleMessages
{
IBus总线;
公共样本(IBus巴士)
{
这辆公共汽车=公共汽车;
}
公共覆盖无效配置HowtoFindsaga()
{
}
公共无效句柄(SampleMessage消息)
{
Data.Message=消息;
发送(新请求());
}
公共无效句柄(响应消息)
{
Write(string.Format(“Response arrived.Holded message:{0}”,Data.message.Test));
MarkAsComplete();
}
}
类消息持有者:ISagaData
{
公共Guid Id{get;set;}
公共int修订版{get;set;}
公共T消息{get;set;}
}
类采样消息
{
公共字符串测试{get;set;}
}
}
命名空间控制台应用程序2
{
班级计划
{
静态IBus总线;
静态void Main(字符串[]参数)
{
var适配器=新的内置容器适配器();
adapter.Handle(x=>bus.Reply(newresponse());
总线=配置。带(适配器)
.Logging(l=>l.ColoredConsole())
.Transport(t=>t.usemmq(“端点2”,“端点2_错误”))
.MessageOwnership(x=>x.fromReBusConfiguration节())
.CreateBus()
.Start();
}
}
公共类请求
{
}
公众课堂反应
{
}
}

是的,这是真的,我同意你的观点,应该在某处记录它:)

不过,这个特性已经存在了相当长的一段时间了,我并没有太多地使用它——主要是因为我觉得它有点太黑了,无法立即理解,我认为大部分时间都应该使用代码

不过,我的感觉可能是因为我使用该功能的次数太少,所以我可能会在将来的某个时候有另一种感觉:)


你的代码看起来不错,我认为它应该工作得很好。现在,我知道这只是一个简单的POC,但请记住在应用程序生命周期内将容器适配器“托管”在某个位置,并请记住在应用程序关闭时将其处置。

谢谢:)通过适配器“托管”您的意思是说,例如,像我使用总线一样保留对适配器的字段引用吗?是的-如果您使用的是内置容器适配器,您不需要保留适配器-只保留
IBus
引用是可以的,只要您记得在应用程序关闭时处理它,但通常,最好使用能够注入依赖项的真正的IoC容器(包括
IBus
)——在使用IoC容器时,通常会将容器视为某种保存整个应用程序的全局根级对象,当你让Rebus把自己放入容器时,你也应该继续这样做:)