W
Webnetweaver
Guest
Ok I'm using event hubs in my webapi app. This was working(reading event hub) for awhile and now a few days later I keep getting this error consistently:
Unexpected character encountered while parsing value: �. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.Read() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Microsoft.ServiceBus.Messaging.BlobLeaseManager.<DownloadLeaseBlob>d__30.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ServiceBus.Messaging.PartitionManager`1.<InitializeAsync>d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.ServiceBus.Messaging.EventProcessorHost.<InitializeAsync>d__53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ServiceBus.Messaging.EventProcessorHost.<StartAsync>d__54.MoveNext()
Whatever is happening isn't happening during any of my application code. It's occuring at this call:
Task.Run(() => eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options)).Wait()
It's never even executing IEventProcessor.OpenAsync() or IEventProcessor.ProcessEventsAsync() but here all of the methods just for clarity:
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
Console.WriteLine("Processor Shutting Down. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason);
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
Task IEventProcessor.OpenAsync(PartitionContext context)
{
//Console.WriteLine("SimpleEventProcessor initialized. Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset);
WebApiApplication.mymsg += "SimpleEventProcessor initialized";
//WebApiApplication.numMessages = 0;
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
WebApiApplication.mymsg += " number of messages: "+messages.Count();
//WebApiApplication.numMessages = messages.Count();
foreach (EventData eventData in messages)
{
string data = Encoding.UTF8.GetString(eventData.GetBytes());
WebApiApplication.mymsg += string.Format("\nMessage received. Partition: '{0}', Data: '{1}'",
context.Lease.PartitionId, data);
}
//Call checkpoint every 5 minutes, so that worker can resume processing from 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
The event hub is being instantiated and called like so:
eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
//return WebApiApplication.mymsg;
//Console.WriteLine("Registering EventProcessor...");
var options = new EventProcessorOptions();
options.MaxBatchSize = 10000;
//options.PrefetchCount = 10000;
options.ExceptionReceived += (sender, e) => {
WebApiApplication.mymsg += e.Exception.ToString();
};
//eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options).Wait();
WebApiApplication.mymsg = "starting...";
//WebApiApplication.numMessages = 1;
Task.Run(() => eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options)).Wait();
started = true;
Task.Run(() => eventProcessorHost.UnregisterEventProcessorAsync()).Wait();
I get no build errors and other endpoints work fine.
WebApiApplication.mymsg gets set to "starting..." and never changes value and i get the forementioned error.
Just to reiterate, this was working fine for days just until I tested it again yesterday. I needed to generate a new auth token for requests. I did that and now reading the event hub consistently gives me this error.
Any guidance or assistance?
*moved to the c# forums which I think is the more appropriate place for this.
Continue reading...
Unexpected character encountered while parsing value: �. Path '', line 0, position 0.
at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.Read() at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Microsoft.ServiceBus.Messaging.BlobLeaseManager.<DownloadLeaseBlob>d__30.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ServiceBus.Messaging.PartitionManager`1.<InitializeAsync>d__13.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.ServiceBus.Messaging.EventProcessorHost.<InitializeAsync>d__53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.ServiceBus.Messaging.EventProcessorHost.<StartAsync>d__54.MoveNext()
Whatever is happening isn't happening during any of my application code. It's occuring at this call:
Task.Run(() => eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options)).Wait()
It's never even executing IEventProcessor.OpenAsync() or IEventProcessor.ProcessEventsAsync() but here all of the methods just for clarity:
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
Console.WriteLine("Processor Shutting Down. Partition '{0}', Reason: '{1}'.", context.Lease.PartitionId, reason);
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
Task IEventProcessor.OpenAsync(PartitionContext context)
{
//Console.WriteLine("SimpleEventProcessor initialized. Partition: '{0}', Offset: '{1}'", context.Lease.PartitionId, context.Lease.Offset);
WebApiApplication.mymsg += "SimpleEventProcessor initialized";
//WebApiApplication.numMessages = 0;
this.checkpointStopWatch = new Stopwatch();
this.checkpointStopWatch.Start();
return Task.FromResult<object>(null);
}
async Task IEventProcessor.ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages)
{
WebApiApplication.mymsg += " number of messages: "+messages.Count();
//WebApiApplication.numMessages = messages.Count();
foreach (EventData eventData in messages)
{
string data = Encoding.UTF8.GetString(eventData.GetBytes());
WebApiApplication.mymsg += string.Format("\nMessage received. Partition: '{0}', Data: '{1}'",
context.Lease.PartitionId, data);
}
//Call checkpoint every 5 minutes, so that worker can resume processing from 5 minutes back if it restarts.
if (this.checkpointStopWatch.Elapsed > TimeSpan.FromMinutes(5))
{
await context.CheckpointAsync();
this.checkpointStopWatch.Restart();
}
}
The event hub is being instantiated and called like so:
eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
//return WebApiApplication.mymsg;
//Console.WriteLine("Registering EventProcessor...");
var options = new EventProcessorOptions();
options.MaxBatchSize = 10000;
//options.PrefetchCount = 10000;
options.ExceptionReceived += (sender, e) => {
WebApiApplication.mymsg += e.Exception.ToString();
};
//eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options).Wait();
WebApiApplication.mymsg = "starting...";
//WebApiApplication.numMessages = 1;
Task.Run(() => eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options)).Wait();
started = true;
Task.Run(() => eventProcessorHost.UnregisterEventProcessorAsync()).Wait();
I get no build errors and other endpoints work fine.
WebApiApplication.mymsg gets set to "starting..." and never changes value and i get the forementioned error.
Just to reiterate, this was working fine for days just until I tested it again yesterday. I needed to generate a new auth token for requests. I did that and now reading the event hub consistently gives me this error.
Any guidance or assistance?
*moved to the c# forums which I think is the more appropriate place for this.
Continue reading...