2

我试图创建一个非常基本的 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:在 Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func) 的 System.Net.HttpWebRequest.GetResponse() 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](FuncRaven.Client.Connection.ServerClient.ExecuteWithReplication[T] 处的 2 操作,String operationUrl,布尔型 AvoidThrowing,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.WhereSelectArrayIterator2.MoveNext() at System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext() at System .Linq.Enumerable.d_ 81 1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at NServiceBus.Unicast.UnicastBus.Publish[T](T[] messages) at ClassLibrary1.MessageSender.b_1() in at System.Threading.Tasks.Task.Execute() InnerException: System.Net.Sockets.SocketException HResult=-2147467259 Message=无法建立连接,因为目标机器主动拒绝它 127.0.0.1:8080 Source= System ErrorCode=10061 NativeErrorCode=10061 StackTrace: 在 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&socket, IPAddress&地址, ConnectSocketState状态, IAsyncResult asyncResult, Exception&异常)

这表明 NServiceBus 仍在尝试连接到 RavenDB。

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

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

注意:我还没有订阅者。

4

1 回答 1

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>
于 2012-09-06T22:27:08.597 回答