Having each worker instance doing something different is against-the-grain for what cloud services are designed for. That is: It's designed for stateless scale-out: Each instance doing the same thing, but being able to scale for more traffic/capacity/cpu/whatever. In your case, that would mean having each worker instance listening in on all ports for all possible incoming traffic, and processing all traffic that comes in.
That said: You can configure an InstanceInputEndpoint
to forward port-specific traffic to specific worker instances. The schema detail for configuring InstanceInputEndpoint
is here. You might still need some decision-making logic in your worker instances, to determine what work it should be doing (and how you do this is specific to your app). And if you need to determine, inside an instance, the instance ID, you'd need to look at RoleEnvironment.CurrentRoleInstance.Id
(assuming the Id doesn't change over time).