技术开发 频道

Azure Services Bus(服务总线)中的工作流

  而如何对这两个服务进行安排组装,就是通过WorkFlow的进行的。如果有开发过工作流经验的开发者应该会很容易理解这个概念。不过这里还是要解释一下,就是在云中运行的工作流与我们平时所了解的工作流(主要是在Activities方面)还是有些差异的,当然这并不意味着云中的工作流要更难于理解,恰恰相反,就目前而言,还是很容易的,下面是其在VS中的设计器中的截图:
    

  有关这几个新添加的工作流activity,可能就要几个篇幅来介绍和说明,因为今天的目的不在于
此,所以就先略过这块内容了。

  另外就是目前在云中只支持CloudSequentialWorkFlow,如下图:

 

  目前还不支持状态机工作流,但并不确保将来就不会出现。当然将来会不会出现workflow4中的
flowchart型工作流就更不好说了。

  假设我们最终要实现的工作流程如下:
   
  1.接受客户端post过来的请求,并获取其中指定的节点信息,本DEMO中节点路径为:<root><order><total>节点值</total></order></root>

  2.通过对该节点值进行比较判断,当值大于1000时则将工作流程转入一个CloudDelay活动中,以进行延时操作(设置CloudDelay活动的TimeOut属性)。当值小于或等于1000时则顺序执行上面所介
绍的两个服务(BillingService,ShippingService)

  将上面的流程中工作流进行表示(创建)的结果如下图:

  

  好了,现在我们有了工作流和服务,接下来就是通过编码将服务运行起来以及将工作流发布到Azure上了。下面是服务的创建运行代码:

internal static void Main()
        {
            var billingServiceHost
= new ServiceHost(typeof(BillingService));
            Console.WriteLine(
"BillingService hosted at:");
            Console.WriteLine(
""t" + billingServiceHost.Description.Endpoints[0].Address.Uri);
            billingServiceHost.Open();

            var shippingServiceHost
= new ServiceHost(typeof(ShippingService));
            Console.WriteLine(
"ShippingService hosted at:");
            Console.WriteLine(
""t" + shippingServiceHost.Description.Endpoints[0].Address.Uri);
            shippingServiceHost.Open();

            Console.WriteLine();
            Console.WriteLine(
"Press [Enter] to exit");
            Console.ReadLine();

            billingServiceHost.Close();
            shippingServiceHost.Close();
        }

  上面代码中的Address.Uri属性是在app.config中进行配置的:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<system.serviceModel>
    
<bindings>
      
<netEventRelayBinding>
        
<binding name="default" />
      
</netEventRelayBinding>
    
</bindings>

    
<services>

      
<service name="Services.ShippingService">
        
<host>
          
<baseAddresses>
            
<add baseAddress="sb://servicebus.windows.net/services/[ENTER YOUR SERVICEBUS USERNAME HERE]"/>
          
</baseAddresses>
        
</host>

        
<endpoint address="Shipping"
                  contract
="Services.ShippingService"
                  binding
="netEventRelayBinding"
                  behaviorConfiguration
="transportClientBehavior0"
                  bindingConfiguration
="default" />

      
</service>

      
<service name="Services.BillingService">
        
<host>
          
<baseAddresses>
            
<add baseAddress="sb://servicebus.windows.net/services/[ENTER YOUR SERVICEBUS USERNAME HERE]"/>
          
</baseAddresses>
        
</host>

        
<endpoint address="Billing"
                  contract
="Services.BillingService"
                  binding
="netEventRelayBinding"
                  behaviorConfiguration
="transportClientBehavior0"
                  bindingConfiguration
="default" />

      
</service>
    
</services>

    
<behaviors>
      
<endpointBehaviors>
        
<behavior name="transportClientBehavior0">
          
<!--
            Specify
              - CardSpace (default)
              - UserNamePassword
              - X509Certificate
              - AutomaticRenewal (tgt)
              - FederationViaCardSpace
            for credentialType.
          
-->
          
<transportClientEndpointBehavior credentialType="UserNamePassword">
            
<clientCredentials>
              
<userNamePassword userName="[ENTER YOUR SERVICEBUS USERNAME HERE]"
                                password
="[ENTER YOUR SERVICEBUS PASSWORD HERE]" />
            
</clientCredentials>
          
</transportClientEndpointBehavior>
        
</behavior>
      
</endpointBehaviors>
    
</behaviors>
  
</system.serviceModel>

</configuration>

 

  注:config文件中的[ENTER YOUR SERVICEBUS USERNAME HERE]内容就是我们在AzureService平台上创建的solution名称(这部分内容参见这篇文章),这里我们继续使用上一篇文章中创建的那个项目名称MSF_DataSyncExample,而PASSWORD就是我们在创建MSF_DataSyncExample之后所设置的口令。

0
相关文章