Created
January 26, 2016 04:41
-
-
Save buchizo/b2aabfb3d10ede34bf51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", "test", ""), new MessagingFactorySettings() | |
{ | |
TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(SasKeyName, SasKey), | |
TransportType = TransportType.Amqp | |
}); | |
var eventHubClient = factory.CreateEventHubClient(EventHubName); | |
var group = eventHubClient.GetDefaultConsumerGroup(); | |
var reciver = group.CreateReceiver(state.ToString()); | |
while (true) | |
{ | |
var m = reciver.Receive(); | |
if (m == null) continue; | |
var bytes = m.GetBytes(); | |
if (!bytes.Any()) | |
{ | |
Console.WriteLine("partition: " + state + ":\t(empty data)"); | |
continue; | |
} | |
if (bytes[0] == 0xA1 || bytes[0] == 0xA0) | |
{ | |
var msg = bytes.Skip(2).Take(bytes[1]).ToArray(); | |
Console.WriteLine("partition: " + state + ":partition key: " + m.PartitionKey + ":0xA1/A0: " + Encoding.UTF8.GetString(msg)); | |
} | |
else | |
{ | |
var msg = Encoding.UTF8.GetString(bytes); | |
Console.WriteLine("partition: " + state + " :partition key: " + m.PartitionKey + ": " + msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment