2
votes

Im trying to create a really basic NServicebus.Host application which sends a message every second. I dont want to use any of the NServiceBus persistance stuff which uses RavenDB (ie timeouts/sagas).

Ive done the following:

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

and

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);
            }
        });
    }
}

however I get an exception on the publish line:

System.Net.WebException was unhandled by user code
HResult=-2146233079 Message=Unable to connect to the remote server
Source=System StackTrace: at System.Net.HttpWebRequest.GetResponse() at Raven.Client.Connection.HttpJsonRequest.ReadStringInternal(Func1 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](Func2 operation, String operationUrl, Boolean avoidThrowing, T& result) at Raven.Client.Connection.ServerClient.ExecuteWithReplication[T](String method, Func2 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.WhereEnumerableIterator1.MoveNext() at System.Linq.Enumerable.<SelectManyIterator>d__142.MoveNext() at System.Linq.Enumerable.d_811.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 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=No connection could be made because the target machine actively refused it 127.0.0.1:8080 Source=System ErrorCode=10061 NativeErrorCode=10061 StackTrace: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

This suggests to me that NServiceBus is still trying to connect to RavenDB.

What else do I need to disable to make this example work?

Why is it even trying to connect to RavenDB for a basic publish?

Note: I have no subscribers yet.

1

1 Answers

3
votes

It looks like NServiceBus also uses RavenDB for subscription storage by default. By specifying an alternate storage mechanism I was able to get this example working.

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

and in the 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>