如何更新Event Hub Microsoft Azure中的数据

时间:2015-11-17 09:31:05

标签: c# azure azure-eventhub

我是Microsoft Azure的新成员 我需要在事件中心Microsoft Azure中更新数据 这是我在事件中心发送数据的代码:

        // Parameter
        string eventHubName = "";
        string eventHubNamespace = "";
        string sharedAccessPolicyName = "";
        string sharedAccessPolicyKey = "";


        //Bus initialization Service
        var settings = new MessagingFactorySettings()
        {
            TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(sharedAccessPolicyName, sharedAccessPolicyKey),
            TransportType = TransportType.Amqp
        };

        var factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", eventHubNamespace, ""), settings);
        EventHubClient client = factory.CreateEventHubClient(eventHubName);

        contact obj = new contact();
        obj.IdC = 12;
        obj.DateContact = DateTime.Now;

        // Serialize to JSON
        var serializedString = JsonConvert.SerializeObject(obj);

        EventData data = new EventData(Encoding.UTF8.GetBytes(serializedString))
        {
            PartitionKey = obj.IdC.ToString()
        };

        // Send the event data to an Event Hub
        client.SendAsync(data);

我可以这样做吗? 帮帮我 感谢。

0 个答案:

没有答案