Orleans streams are not receiving events with localClustering and in-memory only if the grains are in same project
sathishkumarr28 opened this issue · 1 comments
I have two silo orleans projects with one project configured as Stream publisher and the other as stream receiver. Both the projects are configured to run with LocalClustering and in-memory streams.
Below is the code snippet of two silo projects,
the code snippet of silo1 project,
var host = new HostBuilder()
.UseOrleans(ConfigureSilo)
.ConfigureLogging(logging => logging.AddConsole())
.Build();
await host.StartAsync();
var client = host.Services.GetRequiredService<IClusterClient>();
var managementGrain = client.GetGrain<IManagementGrain>(0);
var hosts = await managementGrain.GetHosts();
foreach (var item in hosts)
{
Console.WriteLine($"Silo: {item.Key}, Status: {item.Value}");
}
//Produce events in a ProducerGrain [Which is also in the same silo1 project, its corresponding IProducerGrain is also in the same project]
var key = Guid.NewGuid();
var producer = client.GetGrain<IProducerGrain>("my-producer");
var streamId = StreamId.Create("Streams", key);
_stream = this.GetStreamProvider("Streams")
.GetStream<int>(streamId);
await _stream.OnNextAsync(value);
static void ConfigureSilo(HostBuilderContext context, ISiloBuilder siloBuilder)
{
siloBuilder
.UseLocalhostClustering(siloPort: 22222, gatewayPort: 40000,serviceId: Constants.ServiceId, clusterId: Constants.ClusterId)
.AddMemoryStreams("Streams")
.AddMemoryGrainStorage("PubSubStore");
}
the code snippet for silo2 project,
var host = new HostBuilder()
.ConfigureLogging(logging => logging.AddConsole())
.UseOrleans((context, client) =>
{
client
.UseLocalhostClustering(siloPort: 11111, gatewayPort: 30000, serviceId: Constants.ServiceId, clusterId: Constants.ClusterId)
.AddMemoryStreams("Streams")
.AddMemoryGrainStorage("PubSubStore");
})
.Build();
//Consume events in a ConsumerGrain [Which is also in the same silo1 project, its corresponding IConsumerGrain is also in the same project]
[ImplicitStreamSubscription("Streams")]
public class ConsumerGrain : Grain, IConsumerGrain, IAsyncObserver<string>, IStreamSubscriptionObserver
{
public Task OnNextAsync(string eventData, StreamSequenceToken? token= null)
{
Console.WriteLine($"Received event: {eventData}");
return Task.CompletedTask;
}
public async Task OnSubscribed(IStreamSubscriptionHandleFactory handleFactory)
{
Console.WriteLine("Subscribed");
var handle = handleFactory.Create<string>();
await handle.ResumeAsync(this);
}
....
}
I have made the silo2 project run first and then started silo1 project.
Expected to return 2 silos information in the output window for the line [Console.WriteLine($"Silo: {item.Key}, Status: {item.Value}");
], but it is showing only one silo present under the cluster.
I'm new to Orleans, kindly help me in resolving this issue.
When running multiple silos locally with UseLocalhostClustering
, you will need one of the silos to be the primary silo and ensure it is running before bringing the other silos online.
For example, you could have silo2 be your primary silo, in which case you would update the configuration of silo1 as to where it can expect to find the primary silo:
siloBuilder.UseLocalhostClustering(
siloPort: 22222,
gatewayPort: 40000,
primarySiloEndpoint: new(IPAddress.Loopback, 11111),
serviceId: Constants.ServiceId,
clusterId: Constants.ClusterId);
Here is an example of when the Orleans maintainers have answered a similar question: #6510 (comment)