ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.32k stars 1.63k forks source link

Any suggestion for changing config runtime #712

Closed leechow007 closed 5 years ago

leechow007 commented 5 years ago

I plan to use RabbitMQ to receive the message to change gateway config. I need update the config by itself microservice. From what I've seen, There are two ways to reload config on change.

  1. when recevied something new, update ocelot.json file manually, then use the following code: config.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
  2. via an HTTP API like this : AddAdministration("/administration", options); but calling itself API is kind of strange. Both two ways doesn't update the config directly, so is there any way to do this simplely? Thank you.
briansantura commented 5 years ago

@leechow007 Simply adding reloadOnChange: true won't actually update the configuration unless you add the property to the IoC container.

Every configuration file specified gets loaded into IConfigurationRoot. You can do this in order to see the changes made to the configuration file in runtime.

services.AddSingleton(_ => Configuration);

Does this answer your question?

leechow007 commented 5 years ago

@leechow007 Simply adding reloadOnChange: true won't actually update the configuration unless you add the property to the IoC container.

Every configuration file specified gets loaded into IConfigurationRoot. You can do this in order to see the changes made to the configuration file in runtime.

services.AddSingleton(_ => Configuration);

Does this answer your question?

Thank u so much!!!

I tried the first method, and its routing rules changed immediately while i manually modifed the ocelot.json file. So I guess maybe it works cause .netcore help me did what you said.

And the later method you mentioned, could you give me more details? I wanna to modify the settings, but it seems like I can only get the settings info and change nothing.

briansantura commented 5 years ago

Glad I could help!

This document offers great insight into dependency injection in .netcore and the lifetime of each operation. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2#service-lifetimes

May I close this issue?

leechow007 commented 5 years ago

Glad I could help!

This document offers great insight into dependency injection in .netcore and the lifetime of each operation. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.2#service-lifetimes

May I close this issue?

Thanks a lot. I'll try it.