Skip to content

Instantly share code, notes, and snippets.

@buchizo
Created January 26, 2016 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buchizo/b2aabfb3d10ede34bf51 to your computer and use it in GitHub Desktop.
Save buchizo/b2aabfb3d10ede34bf51 to your computer and use it in GitHub Desktop.
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