[Azure]_Service Bus Event Hubs Getting Started 範例使用筆記
之前已經寫了一系列的Azure EventHubs文章
最近要把他移植到Universal App上面
查資料的同時順便查到這隻Sample,沒有太多的花俏的功能
簡單的傳送訊息,很適合初學者來trace整個data path,包含傳送跟接收都在這個範例裏頭了
https://code.msdn.microsoft.com/windowsapps/Service-Bus-Event-Hub-286fd097
範例細部的code trace就留給各位,這裡只筆記一些你需要修改成自己的azure連線內容
這個範例只需要先請你去Azure創一個Service Bus,不需要在裏頭建立EventHubs
1.首先先打開抓回來的sample project,
然後打開app.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <appSettings> <!-- Service Bus specific app setings for messaging connections --><!-- Service Bus specific app setings for messaging connections --><add key="Microsoft.ServiceBus.ConnectionString" value="PLEASE PROVIDE THE SERVICE BUS CONNECTION STRING" /> <add key="AzureStorageConnectionString" value="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1:10000/" /> </appSettings> <system.serviceModel> <extensions>
<!-- Service Bus specific app setings for messaging connections --><!-- Service Bus specific app setings for messaging connections --><add key="Microsoft.ServiceBus.ConnectionString" value="PLEASE PROVIDE THE SERVICE BUS CONNECTION STRING" /> <add key="AzureStorageConnectionString" value="UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://127.0.0.1:10000/" />
這兩個部分請塞入Service Bus連線字串還有你要讓EventHub暫存資料的Storage
例如
<!-- Service Bus specific app setings for messaging connections --><!-- Service Bus specific app setings for messaging connections --><add key="Microsoft.ServiceBus.ConnectionString" value="Endpoint=sb://dxrdaa03-ns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=qMy6B5W6H0VZqLxYzgEXZlvubKJQpvNVDFo3ov5N6aE=" /> <add key="AzureStorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=dxrdaa03storage;AccountKey=zNIgaYb2Q1j+Kv3nMyRG3IJOoviw6LKfvD1Rq9y9zeNw5Pey+noAQhdBNEr0kXFrsuvOzeD0WlKA0B0+ccq6eA==" />
然後Build起來。
2.需要用cmd去執行該程式,並且帶入三個參數,分別是EventHubs Name(如果不存在,會自動建立)、測試傳送幾個訊息、要用上幾個Partition緩衝這些資料
cd /d e:\Users\Nathaniel\Desktop\Service Bus Event Hubs Getting Started\C#\bins
BasicEventHubSample.exe ehtest 10 8
就會開始傳送資料,過一會兒也會收到這些來自EventHubs的資料
大概是這樣子~
Leave a comment
很抱歉,必須登入網站才能發佈留言。