Search code examples
javaspringspring-bootcloud-foundrypcf

How to send events to all instances of the application in PCF


I am not able to find a way to send/broadcast a message to all application instances in Pivotal Cloud Foundry. How can we notify to all app instances of some events? If we use the HTTP request, PCF router will dispatch it to a single instance of the app. How can we solve this problem?


Solution

  • What @Florian said is probably the safer option, but if you want something quick and easy, you can send HTTP requests directly to an app instance by using the X-CF-APP-INSTANCE header. The format for the header is YOUR-APP-GUID:YOUR-INSTANCE-INDEX.

    https://docs.cloudfoundry.org/concepts/http-routing.html#app-instance-routing

    So given an app guid, you could iterate over the number of instances, say 0 to 5, and send an HTTP request to each one. Make sure to check the response to confirm that each one succeeded.

    This also requires that you know the app guid for your app (i.e. cf app <name> --guid) and the number of instances of your app.