Database Reference
In-Depth Information
The code will look like the following in the MyPublisher , Subscriber1 , and Sub-
scriber2 projects. Note the addition of .UseTransport<SqlServer>() to send
messages to SQL Server and .UseNHibernateSubscriptionPersister() to
save the subscription data in SQL Server.
using NServiceBus;
namespace MyPublisher
{
class EndpointConfig : IConfigureThisEndpoint,
AsA_Publisher,IWantCustomInitialization
{
public void Init()
{
Configure.With()
.DefaultBuilder() // Ensure the default
builder is there
.UseTransport<SqlServer>() // Use SQL
Server Queues
.UseNHibernateSubscriptionPersister() //
Persist the Subscription in SQL Server
.DefiningEventsAs(t => t.Namespace != null
&& t.Namespace.StartsWith("MyMessages"));
}
}
}
The DefiningEventAs() configuration is used to define the convention of the events
that are used for pub/sub messaging, as messages starting with MyMessages . These
messages are configured to process them as event messages for publish or subscribe.
We need to ensure that app.config is updated to send the messages and subscription
information to the correct database. We will set this in the NServiceBus/Transport
and NServiceBus/Persistence/NHibernate/Subscription sections of the
app.config file.
Don't forget to change the Subscriber1 and Subscriber2 endpoints and to use
.UseTransport<SqlServer>() in similar methods as well. Then, we will just gen-
erate some messages to populate the database.
Search WWH ::




Custom Search