SpringBoot: How to reload application.property file in few second without restart application? - properties

I am working on a java web service application which is using SpringBoot framework. I put properties into the application.properties file parallel to the jar. Afterward, I restart the application and new properties are picked by web service.
Now my requirement is, my web service keep reload the property file after few time (lets say 5000ms) and I do not want to restart the web service. Is there any way in SpringBoot to achieve this?
Thanks,
Harsh

If you are using spring cloud starter dependencies, you will get a /refresh endpoint for this purpose to POST to. It refreshes the configuration from property files without interrupting the service.

Related

Run exe file alongside .NET Core Web Application

I have an executable file which I would like to run alongside a .NET Core web application. It needs to start when the web application loads and will continuously run until the web application ends. I also need to be able to check if the executable file is still running through the UI, and have an option to start, stop or restart.
I have done a bit of googling already on this and all that keeps returning is examples where the exe file is expected to end at some point, not anything that continuously runs.
Any pointers in the right direction would be great.
Andy's comment is correct. It's recommended to using Background tasks with hosted services in ASP.NET Core.
And you also can use signalr to record the status of your service. You can start, stop by using StartAsync and StopAsync. And it's impossible to restart. The background service was launched with asp.net core.
For more details, you can check the blog:
Communicate the status of a background job with SignalR

How to update a running asp.net core application on Windows?

I have a Asp.Net Core MVC application running on Windows Server 2008 R2 with IIS. But every time I update this application, I need to manually stop the applicationPool in IIS, and restart the applicationPool after I finish updating the app. Otherwise it will tel me "the xxx.dll is in use by other progress".
Is there any way to make this process easier?
A workaround For Windows with no down time and I am regularly using is:
Rename running .NET core application dll to filename.dll.backup
Upload the new .dll (web application is available and serving the requests while file is being uploaded)
Once upload is complete recycle the Application Pool. Either Requires RDP Access to server or function to recycle application pool in your hosting control panel.
IIS overlaps the app pool when recycling so there usually isn’t any downtime during a recycle. So requests still come in without every knowing the app pool has been recycled and the requests are served seamlessly with no downtime.
I am still searching for more better method than this..!! :)
January 2022 - for Linux
For Linux, we use Openresty nginx with Lua script to hold (sleep) incoming requests for few seconds until the service running .NET Core or .NET 5 or .Net 6 application restarts and then we release the threads we had hold.
Refer: https://github.com/basecamp/intermission
Finally I found my anwser:
I just need add a file named app_offline.htm to the IIS web root(not your project wwwroot folder), and remove it after you replace all of your file.
due to this issue you may need try both App_Offline.htm or app_offline.htm .
and this will allow you to use FTP client to update
Opening the web.config file in an editor and saving it will cause the web application to reload, even if you don't change anything. All DLLs should be replaceable, until a user hits the site, causing the web application to start again. I sometimes use that as a workaround.
A more full fledged solution would be to use Web Deploy, either through Visual Studio or by command line. This can take a litte while to set up, but offers more automation.
https://learn.microsoft.com/en-us/aspnet/core/publishing/iis#deploy-the-application-1
There is no way to hotswap in place DLL's.
Your best bet is to deploy to a new folder each time (For example a versioned folder), and change the website directory in IIS once you have fully copied your website onto the server.

WCF in webjob returns list of records to webapp

Is this possible to put WCF in webjob that will return list of records to webapp.Actually I have project that returns search results (searching is done via lucene.net). Is there any guide or way to get results in my webapp from webjob?
Also can anyone guide me on my localhost I am running my webapp and web job is part of same solution. When I run web application, main function of WebJob is not hitting. Web app and web job can run simultaneously? If these are not runs simultaneously then How can I invoke my searching project initially ? How can my web project relate with my web jobs? I know about invoking by queue but some functions should be run initially when web application is started.
I want to test this behavior on my localhost
Is this possible to put WCF in webjob that will return list of records to webapp.Actually I have project that returns search results (searching is done via lucene.net). Is there any guide or way to get results in my webapp from webjob?
As I known, Azure WebJobs provide you with an easy way to run scripts or programs as background process in the context of your Azure Web Apps. You could not get results directly from WebJobs in your Web Application, you need to store your results in a central data center (Azure Queue, Table Storage,Service Bus,etc.), then you need to retrieve the data explicitly in your Web App. Here is a official tutorial about web application working with Azure WebJob.
Also can anyone guide me on my localhost I am running my webapp and web job is part of same solution. When I run web application, main function of WebJob is not hitting. Web app and web job can run simultaneously?
You could right click your solution and select Properties, choose Startup Project under Common Properties, choose Multiple startup projects and configure the Action for your web application and your WebJob. For more details, you could refer to this issue.
UPDATE:

How do you call a WCF service from a test runner?

I am getting into Selenium WebDriver to write black box integration tests. I'm using MSTest (for now) as a test runner. There's a point where I want to call a WCF service to support the work. I get an error:
Could not find default endpoint element that references contract 'Abc.AbcService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
I realize that calling external services has no business inside a unit test, so I want to emphasize that I'm only using MSTest as a convenient temporary home for automated ui tests, which simulate real life situations of someone using the entire application, front-to-back, using a website driver in tandem with web services.
I guess the problem has to do with finding the .config file when the application is the test runner. Or maybe it is a general problem of having a config file for code in a dll that is hosted in process that you don't control.
If you are calling the WCF service from your test project, you can just add a app.config file with the service configuration in you test project. The configuration will be used to configure the services when called (the app.config file will be deployed with your test dll).

Silverlight and WCF error

I am working at silverlight application and my ask is about wcf and silverlight..
I crated silverlight app and wcf library in one solution..
Then linked service to app via Add service reference..
When I start only service, it's working without problem..
Problem just start when I want to run application.. I've got error about client access policy, which I have add as well..
So my ask is: Is there a way how to start app (and debug) and service together witout that error? and without duty to deploy? Only in debug mode?
The clientaccesspolicy.xml and/or crossdomain.xml files are not required inside your client application, and they do not belong in your web service directory. Rather, they must be copied into the root of your web server. Mostly, that would be the directory C:\inetpub\wwwroot instead of C:\inetpub\wwwroot\PDFService.