20

I created a stateful service with the out-of-the-box partitioning:

<StatefulService ServiceTypeName="ExamplesServiceType" TargetReplicaSetSize="[ExamplesService_TargetReplicaSetSize]" MinReplicaSetSize="[ExamplesService_MinReplicaSetSize]">
            <UniformInt64Partition PartitionCount="[ExamplesService_PartitionCount]" LowKey="-9223372036854775808" HighKey="9223372036854775807" />
         </StatefulService>

The service manifest sets the params to (out-of-the-box as well):

 <Parameter Name="ExampleService_PartitionCount" Value="1" />
 <Parameter Name="ExampleService_MinReplicaSetSize" Value="2" />
 <Parameter Name="ExampleService_TargetReplicaSetSize" Value="3" />
 <Parameter Name="WebService_InstanceCount" Value="1" />

Now I want to call to to my stateful service from my stateless service in the same cluster:

 ServiceUriBuilder builder = new ServiceUriBuilder(ExampleServiceName);
 var service = ServiceProxy.Create<IExampleService>(builder.ToUri(),new ServicePartitionKey(1));

 return service.MyCallAsync(id);

I'm getting the following error:

The primary or stateless instance for the partition 'a67f7afa-3370-4e6f-ae7c-15188004bfa1' has invalid address, this means that right address from the replica/instance is not registered in the system

The stateful service I'm trying to reach logs to the event logs and the logs carry "partitionId": "a67f7afa-3370-4e6f-ae7c-15188004bfa1".

What am I missing?

tymtam
  • 31,798
  • 8
  • 86
  • 126

3 Answers3

30

I wasn't registering a remote as explained at http://vunvulearadu.blogspot.com/2016/04/azure-service-fabric-primary-or.html

        protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return new[] { new ServiceReplicaListener(context => this.CreateServiceRemotingListener(context)) };
    }
tymtam
  • 31,798
  • 8
  • 86
  • 126
  • 1
    Thanks a lot for sharing your solution, this cured my headache. ;) – Kristoffer la Cour Apr 27 '16 at 11:45
  • 7
    CreateServiceRemotingListener is an extension method in this namespace, so make sure you add a using Microsoft.ServiceFabric.Services.Remoting.Runtime; for those who can't find that extension method. – SondreB Jun 11 '16 at 21:03
  • @mayu : I facing the same issue but I'm calling a stateless service inside the actor application, and i dont have CreateServiceReplicaListeners() method to override, any idea on how this must be done for actors? – Vinodh Dec 13 '16 at 15:07
  • @Vinodh: stateless services have similar method `CreateServiceInstanceListeners()` instead, you should override it with `protected override IEnumerable CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(this.CreateServiceRemotingListener) }; }`. – MaGu Dec 23 '16 at 16:28
  • Argh, what a pain. Well done! Just for the people who can't find this method, you need to add `using Microsoft.ServiceFabric.Services.Remoting.Runtime;` – Hugo Nava Kopp Jun 23 '17 at 11:16
  • after this, if any1 getting 'get_ListenAddress()' method exception then downgrade nuget Microsoft.ServiceFabric.Services.Remoting to v2.6.220 – GorvGoyl Sep 06 '17 at 13:24
  • For those of you using Microsoft.ServiceFabric.Services.Remoting version 3.3.638, I found that there was no extension method called CreateServiceInstanceListeners(). I only found CreateServiceRemotingInstanceListenersf() and CreateServiceRemotingReplicaListeners() in Microsoft.ServiceFabric.Services.Remoting.Runtime.ServiceRemotingExtensions – David Klempfner Mar 12 '19 at 01:02
11

In case anyone else comes here wondering what to do for stateless services, this works for me:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    return new[] { new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context)) };
}
KPERI
  • 233
  • 3
  • 9
3

For those of you using Microsoft.ServiceFabric.Services.Remoting version 3.3.638, I found that there was no extension method called CreateServiceInstanceListeners(). I only found CreateServiceRemotingInstanceListeners() and CreateServiceRemotingReplicaListeners() in Microsoft.ServiceFabric.Services.Remoting.Runtime.ServiceRemotingExtensions.

This code compiled for me:

    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return this.CreateServiceRemotingInstanceListeners();
    }
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
  • 1
    Thank you for this! I'm trying to work through the book Programming Microsoft Azure Service Fabric, Second Edition, and one of the very first examples does not compile with the source code specified in the text. Making the change you called out here works. – Phil Ringsmuth Jul 23 '21 at 17:22
  • This is also the way it is described in Microsoft docs: https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting#use-an-assembly-attribute-to-use-the-v2-stack – Juho Rutila Sep 14 '21 at 06:23