Skip to content

Custom EventServiceProvider subscriptions only register with ONE (of 10) EventServiceProviders #4445

@ben-beamable

Description

@ben-beamable

Describe the Bug

In a deployed environment, a single C# MS task runs 10 Basic and Event ServiceProviders.

Using [InitializeServices] to register an EventServiceProvider at C# MS startup only registers the custom event handler for a single EventServiceProvider, instead of all 10 EventServiceProviders that the service forks.

To Reproduce

Steps to reproduce the behavior:

using System;
using Beamable.Common;
using Beamable.Common.Api;
using Beamable.Common.Api.Stats;
using Beamable.Common.Dependencies;
using Beamable.Server;
using Beamable.Server.Api.Stats;
using UnityEngine;

namespace Beamable.StatusWatcher
{
	
	[Serializable]
	public class OnlineStatus
	{
		public bool Online { get; init; }
		public string LastOnline { get; init; }
		public string PlayerId { get; init; }
		public string Status { get; init; }
		public string Description { get; init; }

		public OnlineStatus(
			bool online,
			string lastOnline,
			string playerId,
			string status,
			string description)
		{
			Online = online;
			LastOnline = lastOnline;
			PlayerId = playerId;
			Status = status;
			Description = description;
		}
	}
	
	[Microservice("StatusWatcher")]
	public partial class StatusWatcher : Microservice
	{
		private static PlatformSubscription<OnlineStatus> _subscription;
		private const string PlayerStatusNotif = "player-status";
		
		[InitializeServices]
		public static async Promise SetupCustomEvents(IServiceInitializer initializer)
		{
			await InitializeSubscription(initializer.Provider);
			var statsService = initializer.Provider.GetService<IMicroserviceStatsApi>();
			var context = initializer.Provider.GetService<SocketRequesterContext>();
			context.Subscribe<OnlineStatus>(PlayerStatusNotif, async data =>
			{
				
				var onlineCount = await statsService.GetStat(StatsDomainType.Client, StatsAccessType.Public,
					long.Parse(data.PlayerId), "online");
				
				var newCount = int.Parse(onlineCount) + 1;
			
				await statsService.SetStat(StatsDomainType.Client, StatsAccessType.Public, long.Parse(data.PlayerId), "online",
					newCount.ToString());
				
				Debug.Log($"Player status notification {data}");
			});
		}
		
		public static async Promise InitializeSubscription(IDependencyProvider provider)
		{
			var requester = provider.GetService<IBeamableRequester>();

			var req = new MicroserviceEventProviderRequest
			{
				type = "event",
				evtWhitelist = new []
				{ 
					PlayerStatusNotif
				}
			};
			await requester.Request<MicroserviceProviderResponse>(Method.POST, "gateway/provider", req);
		}
	}
}

Only one EventServiceProvider will handle that notification.

Expected Behavior

When I register custom events via InitializeServices, it should register those for all EventServiceProviders that spawn in the task, not just ONE.

Actual Behavior

Only one EventServiceProvider actually handles the custom event instead of every provider that registers. We can see evidence that this is happening by looking at the ActiveMQ queues, where it shows that only 1 consumer is registered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions