Question

I need to develop a Windows Server Service Bus topic subscriber (yes, Windows Server and not Azure), and in order to abstract away from the reading, start worker thread, ..., cycle and to take advantage of AppFabric management capabilities, i had the following idea:

  • Develop a WCF service
  • Define a Windows Server Service Bus endpoint

And the questions are:

  1. A publisher must use the Service Contract to send messages to the topic?
  2. What should the configuration file look like?

Thanks in advance.

Était-ce utile?

La solution 2

To help future related problems here is the required configuration

Extensions required both in publisher and subscriber configuration:

<extensions>
  <behaviorExtensions>
    <add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </behaviorExtensions>

  <bindingExtensions>
    <add name="netMessagingBinding" type="Microsoft.ServiceBus.Messaging.Configuration.NetMessagingBindingCollectionElement, Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </bindingExtensions>
</extensions>

Note: The Microsoft.ServiceBus assembly is required both in the publisher as well in the subscriber. The package is available in Nuget.

Subscriber side configuration:

<bindings>
  <netMessagingBinding>
    <binding name="messagingBinding" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:03:00" sendTimeout="00:03:00" sessionIdleTimeout="00:01:00" prefetchCount="-1">
      <transportSettings batchFlushInterval="00:00:01" />
    </binding>
  </netMessagingBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="securityBehavior">
      <messageInterceptorBehavior/>
      <transportClientEndpointBehavior>
        <tokenProvider>
          <windowsAuthentication>
            <stsUris>
              <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
            </stsUris>
          </windowsAuthentication>
        </tokenProvider>
      </transportClientEndpointBehavior>
</behavior>

<endpoint listenUri="sb://[SERVER]/[NAMESPACE]/[TOPIC]/Subscriptions/[SUBSCRIPTIONNAME]"
              address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
              behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
              bindingConfiguration="messagingBinding" name="InsuranceService"
              contract="[WCF_CONTRACT_NAME]" />

Publisher configuration:

<bindings>
  <netMessagingBinding>
    <binding name="InsuranceService" closeTimeout="00:03:00" openTimeout="00:03:00"
      receiveTimeout="00:03:00" sendTimeout="00:03:00" prefetchCount="-1"
      sessionIdleTimeout="00:01:00">
      <transportSettings batchFlushInterval="00:00:01" />
    </binding>
  </netMessagingBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="securityBehavior">
      <messageInterceptorBehavior/>
      <transportClientEndpointBehavior>
        <tokenProvider>
          <windowsAuthentication>
            <stsUris>
              <stsUri value="https://[SERVER]:9355/[NAMESPACE]" />
            </stsUris>
          </windowsAuthentication>
        </tokenProvider>
      </transportClientEndpointBehavior>
    </behavior>
  </endpointBehaviors>
</behaviors>

<client>
  <endpoint address="sb://[SERVER]/[NAMESPACE]/[TOPIC]"
    behaviorConfiguration="securityBehavior" binding="netMessagingBinding"
    bindingConfiguration="InsuranceService" contract="PushVoucherService.ISubscriber"
    name="InsuranceService" />
</client>

Autres conseils

The basic mechanics of how to connect WCF and Service Bus are the same between the Azure and the Server versions. You can use this post as a good starting point:

The main difference between the two is going to be with the endpoint addresses, and how to deal with authentication (since there's no ACS in the server). This post has some useful information on it.

Now, to answer your questions specifically:

  • A publisher could technically push directly to the service bus queues, but it's better if you use a contract. The problem here is not how to push, but how to build the message in a way that the service can understand it. Having a WCF contract will let you abstract the serialization / deserialization away.

  • For the configuration, the typical scenario would be to have a WCF service that uses netMessagingBinding. The first post I mentioned has information on the configuration. Just make sure to update the auth and endpoint address pieces to match service bus server's.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top