{"record":{"id":"54fe89eee19500b8","repo":"dotnet/orleans","slug":"this-adapter-only-supports-read","errorCode":null,"errorMessage":"This adapter only supports read","messagePattern":"This adapter only supports read","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"warning","filePath":"samples/Streaming/CustomDataAdapter/Silo/CustomDataAdapter.cs","lineNumber":28,"sourceCode":"// Custom EventHubDataAdapter that serialize event using System.Text.Json\npublic class CustomDataAdapter : EventHubDataAdapter\n{\n    public CustomDataAdapter(Serializer serializer) : base(serializer)\n    {\n    }\n\n    public override string GetPartitionKey(StreamId streamId)\n        => streamId.ToString();\n\n    public override StreamId GetStreamIdentity(EventData queueMessage)\n    {\n        var guid = Guid.Parse(queueMessage.PartitionKey);\n        var ns = (string) queueMessage.Properties[\"StreamNamespace\"];\n        return StreamId.Create(ns, guid);\n    }\n\n    public override EventData ToQueueMessage<T>(StreamId streamId, IEnumerable<T> events, StreamSequenceToken? token, Dictionary<string, object>? requestContext)\n        => throw new NotSupportedException(\"This adapter only supports read\");\n\n    protected override IBatchContainer GetBatchContainer(EventHubMessage eventHubMessage)\n        => new CustomBatchContainer(eventHubMessage);\n}\n\n[GenerateSerializer, Immutable]\npublic sealed class CustomBatchContainer : IBatchContainer\n{\n    [Id(0)]\n    private readonly EventHubMessage _eventHubMessage;\n\n    [Id(1)]\n    public StreamSequenceToken SequenceToken { get; }\n\n    public StreamId StreamId => _eventHubMessage.StreamId;\n\n    public CustomBatchContainer(EventHubMessage eventHubMessage)\n    {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/orleans/blob/fca799fa70ecb6ad975224271703ca43221f58de/samples/Streaming/CustomDataAdapter/Silo/CustomDataAdapter.cs#L10-L46","documentation":"Thrown by the CustomDataAdapter sample's ToQueueMessage override to make the stream adapter explicitly write-only-incompatible — the sample demonstrates a read-only Event Hubs consumer adapter and intentionally forbids producing. Any code path that tries to publish events through this provider hits the NotSupportedException by design.","triggerScenarios":"A grain or client calls GetStreamProvider(...).GetStream<T>(streamId).OnNextAsync(...) while the provider is configured with CustomDataAdapter, whose ToQueueMessage (the produce path) always throws.","commonSituations":"Reusing the read-only sample adapter in a project that also needs to publish; wiring the same adapter to a producer grain by mistake; assuming every EventDataBatchContainerAdapter supports both directions.","solutions":["Do not produce through this provider — it is a consumer-only sample. Publish through a different stream provider configured with a full bidirectional adapter.","If you need bidirectional support, implement ToQueueMessage in your own adapter instead of inheriting the sample's throw.","Verify which provider name a producer grain targets (Constants.StreamProvider) versus the one configured with CustomDataAdapter."],"exampleFix":"// before: producing through the read-only sample adapter\nvar stream = provider.GetStream<int>(streamId);\nawait stream.OnNextAsync(1); // hits ToQueueMessage -> NotSupportedException\n\n// after: publish via a provider whose adapter implements ToQueueMessage\nvar writeStream = writeProvider.GetStream<int>(streamId);\nawait writeStream.OnNextAsync(1);","handlingStrategy":"validation","validationCode":"// Only subscribe/consume on the read-only provider; publish via a separate provider\nif (providerName == \"CustomDataAdapter\")\n    throw new InvalidOperationException(\"Provider is read-only; do not produce.\");","typeGuard":"null","tryCatchPattern":"try\n{\n    await stream.OnNextAsync(value);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"only supports read\"))\n{\n    // Route production to a bidirectional provider instead\n}","preventionTips":["Never publish through a consumer-only adapter; publish via a separate provider.","Implement ToQueueMessage in your own adapter if bidirectional support is needed.","Document provider directionality in the sample's README."],"tags":["streaming","eventhub","data-adapter","read-only","by-design","sample"],"backgroundTag":null,"analyzedSha":"fca799fa70ecb6ad975224271703ca43221f58de","analyzedAt":"2026-08-13T19:55:57.938Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}