没有ravenDB的NServiceBus基本消息发布者

时间:2012-09-06 21:37:08

标签: c# nservicebus

我试图创建一个真正基本的NServicebus.Host应用程序,它每秒发送一条消息。我不想使用任何使用RavenDB的NServiceBus持久性东西(即超时/传真)。

我做了以下事情:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, AsA_Publisher, IWantCustomInitialization
{
    public void Init()
    {
        Configure.With()
            .DisableTimeoutManager();
    }
}

public class MessageSender : IWantToRunWhenTheBusStarts
{
    private readonly IBus _bus;

    public MessageSender(IBus bus)
    {
        _bus = bus;
    }

    public void Run()
    {
        Task.Factory.StartNew(() =>
        {
            while (true)
            {
                _bus.Publish(new MyMessage { Timestamp = DateTime.Now });
                Thread.Sleep(1000);
            }
        });
    }
}

但是我在发布行上遇到了例外:

  

System.Net.WebException未被用户代码
处理   HResult = -2146233079消息=无法连接到远程服务器
  Source = System StackTrace:          在System.Net.HttpWebRequest.GetResponse()          在Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func 1 getResponse) at Raven.Client.Connection.HttpJsonRequest.ReadResponseString() at Raven.Client.Connection.HttpJsonRequest.ReadResponseJson() at Raven.Client.Connection.ServerClient.DirectGet(String serverUrl, String key) at Raven.Client.Connection.ServerClient.<>c__DisplayClass1.<Get>b__0(String u) at Raven.Client.Connection.ServerClient.TryOperation[T](Func 2操作,String operationUrl,Boolean avoidThrowing,T&amp; result)          在Raven.Client.Connection.ServerClient.ExecuteWithReplication [T](String   方法,Func 2 operation) at Raven.Client.Connection.ServerClient.Get(String key) at Raven.Client.Document.DocumentSession.Load[T](String id) at System.Linq.Enumerable.WhereSelectArrayIterator 2.MoveNext()          在System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__14 2.MoveNext()          在System.Linq.Enumerable.d_ 81 1.MoveNext() at System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1来源)          在NServiceBus.Unicast.UnicastBus.Publish [T](T []消息)          在ClassLibrary1.MessageSender.b _1()中          at System.Threading.Tasks.Task.Execute()InnerException:System.Net.Sockets.SocketException          的HResult = -2147467259          消息=无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8080          来源=系统          错误码= 10061          NativeErrorCode = 10061          堆栈跟踪:               在System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)               在System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)               在System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,Socket s4,Socket s6,Socket&amp; socket,IPAddress&amp;   地址,ConnectSocketState状态,IAsyncResult asyncResult,   异常和放大器;例外)

这告诉我,NServiceBus仍在尝试连接到RavenDB。

我需要禁用什么才能使此示例正常工作?

为什么甚至尝试连接到RavenDB进行基本发布?

注意:我还没有订阅者。

1 个答案:

答案 0 :(得分:3)

默认情况下,NServiceBus似乎也使用RavenDB进行订阅存储。通过指定备用存储机制,我能够使这个示例正常工作。

            .MsmqTransport()
                .MsmqSubscriptionStorage()
            .DisableTimeoutManager();

并在app.config

<configuration>
    <configSections>
        <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
        <section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig, NServiceBus.Core" />
    </configSections>
    <MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
    <MsmqSubscriptionStorageConfig Queue="YourQueue" />
</configuration>