Spring boot issue when deployed on to Mesos dcos having multiple microservices - spring-mvc

I am new to spring boot and have recently encountered a weird issue. My application which already has a context path runs smoothly on the localhost with a URL like "localhost:port/contextpath/dashboard". But when I try to deploy it on Mesosphere DCOS, it produces an error. Since the mesos server has multiple microservices, each service is separated by a service name,so the service got deployed onto a path like "server.com/servicename/contextpath/dashboard". However, internally the relative mapping is such that any internal reference, be it a navigation like or request mapping of controller ends up something like "server.com/contextpath/dashboard" which misses out on the service name and hence doesn't work.

Related

Azure function runtime unreachable using app settings

I have an azure function app ( time trigger functions ) which is giving "Azure Function runtime is unreachable" error. We are using appsetting.json in place of local.host.json and the variables are configured in devops pipeline. I can see that the variables gets updated in azure function app files, However function is not executing yet it shows some memory consumption every 3o mins. Please share your suggestions to fix this. Thanks !
As far as I Know,
Azure Functions Runtime is unreachable comes if the function app is blocked by firewall or storage account configuration is incorrect in the Connection String.
I found few solved issues in the SO for similar errors in the context of Azure Functions deployed through Azure DevOps Pipelines where user #JsAndDotNet solved here the above error by correcting the Platform value in Configuration menu of deployed Azure Function App in the portal.
Another user #DelliganeshSevanesan solved this error in the Context of Azure Functions Deployment using IDEs 70934637 where multiple reasons are given as a check to this error along with the resolutions.
Also, I have observed we need to add Azure Function App Configuration Settings in the Pipeline with the form of Key-Value Pair, which is also known as transformation of the local.settings.json of Azure Function App to the Azure CI/CD Pipelines. For this, I have found the practical workarounds given by #VijayanathViswanathan and #Sajid in these SO Issue 1 & 2.

Logging with Serilog and Seq in azure .net api

I am working on an Web Api in .net. I am writing logs using Serilog and Seq. I made the configuration following the Seq official web site.
Basically placing this code in my startup.cs file:
var logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Seq("http://localhost:5431/")
.CreateLogger();
builder.RegisterInstance<Serilog.ILogger>(logger);
I am logging to localhost so I am able to see my logs locally. So far so good.
I deployed my Api to azure and I want to continue logging on the same way. So I worked with the link https://docs.getseq.net/v3/docs/azure-installation and made the configuration. I had to create a virtual machine different from my ServicePlan and my Api. I installed Seq on that VM and run the Seq program on the url http://example.azurewebsites.net:5341/ so I made the change in my startup file too.
.WriteTo.Seq("http://example.azurewebsites.net:5341/")
I also had to create a Firewall Rule in the port 5341 in my VM and an Inbound Rule in the VM Network Security Rule.
I deployed again, at this point I would expect yo have Seq running on http://example.azurewebsites.net:5341/, but that is not certainly happening because I cannot find anything at the url neither from my PC browser nor from VM browser.
What am I missing? or In which configuration steps I have to check again?
In my experience so far, VMs live at *.cloudapp.net subdomains, not *.azurewebsites.net (which is IIRC the Azure App Service).

websphere liberty 8.5.5.9 remote ejb lookup fails

I have created two liberty instances on my local machine. I deployed a war module which contains a remote ejb in server X and deployed another war in server Y which has to remote lookup the ejb from server X.
Below is the code to lookup the ejb from a restful webservice.
Properties p = new Properties();
p.setProperty("java.naming.provider.url", "corbaname:iiop:localhost:2809");
InitialContext context = new InitialContext (p);
context.lookup("corbaname:rir:#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService");
When I try to call the web service I get below exception
DII operation not supported by local object
P.S.
I have enabled ejbRemote feature on both the servers with different port numbers.
I changed my lookup string to "corbaloc:iiop:localhost:2809/NameService#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService" and then I get the below error
Then I changed my lookup string to "corbaname:iiop:localhost:2809/NameService#ejb/global/caching/CachingServiceBean!com%5c.ejb%5c.CachingService" and then I got the below error
After checking apache geronimo-yoko implementation on GitHub, I understood that I have to use corbaloc:iiop:localhost:2809. But still I am getting exceptions caused by
org.omg.CORBA.OBJECT_NOT_EXIST: unable to dispatch - servant or POA not found
I used the following urls with no luck:
corbaloc:iiop:localhost:2809/global/caching/CachingServiceBean!com.ejb.CachingService
corbaloc:iiop:localhost:2809/#ejb/global/caching/CachingServiceBean!com.ejb.CachingService
3.corbaloc:iiop:localhost:2809/caching/CachingServiceBean!com.ejb.CachingService
4.corbaloc:iiop:localhost:2809/ejb/global/caching/CachingServiceBean!com.ejb.CachingService
I think the problem is with the packaging. I packed my ejb in a war module.
I followed the steps described in the PDF mentioned in this page http://www.redbooks.ibm.com/redpieces/abstracts/sg248076.html and everything is working now.
I used corbaname::host:port syntax to lookup the remote ejb instead of corbaloc:iiop:host:port
After packing my ejb in an ear then it started working.

How to properly configure Spring Datasource for an Elastic Beanstalk app?

I'm running into an issue integrating Spring Security with my Elastic Beanstalk app backed by a MySql database. If I deploy my app I'm able to login in correctly for some time but eventually I'll start to receive login errors without an exception being thrown so I'm unable to get any useful information about the issue. I've downloaded the logs as well and can't see anything of value. I can see where the logs show accessing the public page, attempting to access the private section, returning the login page, and then the loginError page; however, nothing about any issue.
Even though I'm unable to login through a browser I am able to login if I run the app from an IDE as well as view the db in MySQL Workbench. This suggests to me the problem is due to some persistent state on the server.
I've had a similar problem before with another Beanstalk app using Spring Security and was able to resolve it by setting application properties as follows:
spring.datasource.test-on-borrow=true
spring.datasource.validation-query=SELECT 1
I'm using a more recent version of Spring than that app and the properties have been changed to specific datasources so I tried adding the following properties:
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1
When that didn't work I added another based on an answer to a similar question here; now the properties are:
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.validation-query=SELECT 1
That seemed to work (possibly due to less login activity) but eventually resulted in the same behavior .
I've looked into the various properties available but before I spend a lot of time randomly setting and/or overriding default settings I wanted to see if there's a reliable way to deal with this.
How can I configure my datasource to avoid login errors after long periods of time?
This isn't a problem of specific configuration values but with where those configurations reside. The default location for the application.properties (/resources; Intellij) is fine for deploying as a jar with an embedded Tomcat server but not as a war with a provided server. The file isn't found/used so no changes to the file affect the one given by AWS.
There are a number of ways to handle this; I chose to add an RDS configuration bean in my SpringBootServletInitializer:
#Bean
public RdsInstanceConfigurer instanceConfigurer() {
return () -> {
TomcatJdbcDataSourceFactory dataSourceFactory =
new TomcatJdbcDataSourceFactory();
// Abondoned connections...
dataSourceFactory.setRemoveAbandonedTimeout(60);
dataSourceFactory.setRemoveAbandoned(true);
dataSourceFactory.setLogAbandoned(true);
// Tests
dataSourceFactory.setTestOnBorrow(true);
dataSourceFactory.setTestOnReturn(false);
dataSourceFactory.setTestWhileIdle(false);
// Validations
dataSourceFactory.setValidationInterval(30000);
dataSourceFactory.setTimeBetweenEvictionRunsMillis(30000);
dataSourceFactory.setValidationQuery("SELECT 1");
return dataSourceFactory;
};
}
Below are the settings that worked for me.
From Connection to Db dies after >4<24 in spring-boot jpa hibernate
dataSourceFactory.setMaxActive(10);
dataSourceFactory.setInitialSize(10);
dataSourceFactory.setMaxIdle(10);
dataSourceFactory.setMinIdle(1);
dataSourceFactory.setTestWhileIdle(true);
dataSourceFactory.setTestOnBorrow(true);
dataSourceFactory.setValidationQuery("SELECT 1 FROM DUAL");
dataSourceFactory.setValidationInterval(10000);
dataSourceFactory.setTimeBetweenEvictionRunsMillis(20000);
dataSourceFactory.setMinEvictableIdleTimeMillis(60000);

Spring Integration: JDBC single query to web service

I would like to know the way for resolving this integration scenario:
Execute different queries to select X elements from a database. I am
looking for an inbound adapter without pooling because it is just
necessary to execute the query once. Although, results of the queries
will be generate only one output.
Work with this data to build a SOAP request (generic web service)
Send this SOAP request to a web service and wait for an asynchronous response.
But also, it is necessary to deploy all this scenario in a WAR file on Tomcat server. I am deploying the application from a spring MVC + spring integration skeleton but I will not have any controller. Is it possible to execute the application when context was loaded on Tomcat?
I am working with the next technologies:
Spring integration
Spring MVC for a WAR deployment
Scheduling (Quartz or #Scheduled)
Spring WS
Regards
Since you say that you'd prefer to select on the application start up and only once, you can use:
<int-event:inbound-channel-adapter channel="jdbcChannel"
event-types="org.springframework.context.event.ContextRefreshedEvent"
payload-expression="''"/>
and <int-jdbc:outbound-gateway query="SELECT * FROM ..."/>
And so on to the WebService.
UPDATE
Since you say that you are around Anotation configuration, consider to use Spring Integration Java DSL.
To configure <int-event:inbound-channel-adapter> from #Configuration you should do this:
#Bean
#SuppressWarnings("unchecked")
public MessageProducer ApplicationEventListeningMessageProducer() {
ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ContextRefreshedEvent.class);
producer.setPayloadExpression("''");
producer.setOutputChannel(jdbcChannel());
return producer;
}
ContextRefreshedEvent info you can get from its JavaDocs or from Spring Framework Manual.

Resources