crunchy
crunchy

Reputation: 703

NServicebus DataBus

I need to move some large files, and I wanted to use NserviceBus as the files are not persisted on the system. I have been trying to get this up and running using the new databus feature in v.3. The files are generated in one process, then passed onto the bus. My problem is that I can't get the bus started. I have a sample application below that basically mirrors my set up, except that in the 'real' application, the bus lives in a different application (not pushed to a server yet so I just run a dev instance)

    #region Declarations

    private IBus Bus { get; set; }

    #endregion

    #region Constructors

    public Sender()
    {       
        if (Directory.Exists(BasePath))
        {
            Bus = Configure.Instance
                .FileShareDataBus(BasePath)
                .UnicastBus().DoNotAutoSubscribe()
                .CreateBus()
                .Start();
        }
    }

    #endregion

    #region Methods

    public void SendMessage()
    {
        // get a list of file names
        List<string> fileList = Directory.GetFiles(@"c:\test\").ToList();


        Bus.Send<GenericListMessage>(message =>
                                        {
                                            message.Name = "TEST";
                                            message.FileList = new DataBusProperty<List<string>>(fileList);
                                        });
    }
    #endregion

My EndpointConfig.cs looks like this:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Client 
{
}

internal class SetupDataBus : IWantCustomInitialization
{
    public static string BasePath = @"c:\storage\";

    public void Init()
    {
        Configure.Instance
            .FileShareDataBus(BasePath)
            .UnicastBus()
            .DoNotAutoSubscribe();
    }
}

I have changed my code in the Sender class to send a non-Databus message, and a simple message, and this worked fine. But when I try to use it to send a Databus message I keep getting a NullReferenceException for the bus. If anyone can give me a pointer I would really appreciate it.

Upvotes: 1

Views: 1149

Answers (1)

Andreas &#214;hlund
Andreas &#214;hlund

Reputation: 5273

You need to change

private IBus Bus { get; set; }

to:

public IBus Bus { get; set; }

To get dependecy injection for the bus.

Upvotes: 1

Related Questions