Register Hazelcast Cluster instances on Eureka - spring-boot

I have a Spring Boot service in which I've started an HazelCast instance.
#Bean
public Config config(){
return new Config();
}
#Bean
public HazelcastInstance hazelcastInstance(Config config){
return Hazelcast.newHazelcastInstance();
}
Now, I want to register my HazelCast instances in Eureka so that my HC clients can retrieve HC cluster instances dynamically.
HazelCast plugin page point me to the eureka plugin but this one is from 2015 and contains a lot of deprecated code recommending me to use EurekaModule and DI.
Does someone have an example?

Have a look at https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/springboot-eureka-partition-groups
Should do what you need

Related

How to specify Ribbon Configuration for a specific Feign client in a Spring Boot project having multiple Feign clients?

I have a spring boot project which is having two Feign Client's.
First Feign client (i.e. ServiceAProxy.class below), which will work on Service Discovery using Eureka or Consul.
#FeignClient(name="service-A")
public interface ServiceAProxy{
#RequestMapping(method= RequestMethod.GET)
String getResponse();
}
Second Feign client( i.e ServiceBProxy.class ), needs to have a set of server list which will be picked from Spring Cloud Configuration server or Apache zookeeper config server and will be passed to the ribbon client of ServiceBProxy.class. For that, I'm trying to add a Ribbon Client Configuration that will modify the ribbon server list. Below is the code for the second feign client.
#FeignClient(name="service-B")
#RibbonClient(name="service-B",configuration= ServiceBProxy.LocalRibbonClientConfig.class)
public interface ServiceBProxy{
#RequestMapping(method = RequestMethod.GET)
String invalidateUsers();
#Configuration
class LocalRibbonClientConfig{
#Value("${server-host1}") // fetched from config
private String host1;
#Value("${server-host2}") // fetched from config
private String host2;
#Bean
public ServerList<Server> ribbonServerList() {
return new StaticServerList<>(
new Server(host1,8080),
new Server(host2,8081)
);
}
}
}
Now, when I run the code, ServiceBProxy.class works as expected and picks the list of servers that was specified in the LocalRibbonClientConfig.class.
But the problem is with the ServiceAProxy.class which was suppose to work on the basis of service discovery also starts to use the LocalRibbonClientConfig.
How can I only allow ServiceBProxy.class to use the custom ribbon configurations and other feign clients in the project to work as per their default behaviour.
Please guide on this.

Server unable to join Hazelcast cluster via multicast enabled?

I have same Hazelcast server project running at 3 different server's, two of them are able to form the cluster but the third server does not join. I have created Hazelcast server project using spring-boot. Here are my Spring Boot Hazelcast config.
#Bean
public Config hazelCastConfig() {
Config config = new Config();
config.getNetworkConfig().setPortAutoIncrement(true);
config.setClusterName("myHazelcastStore");
NetworkConfig network = config.getNetworkConfig();
JoinConfig join = network.getJoin();
join.getMulticastConfig().setEnabled(true);
return config;
}
#Bean
public HazelcastInstance hazelcastInstance(Config hazelCastConfig) {
return Hazelcast.newHazelcastInstance(hazelCastConfig);
}
#Bean
public Map<String, EmployeeAccount> employeeMap(HazelcastInstance hazelcastInstance) {
return hazelcastInstance.getMap("employeeMap");
}
I am using latest stable version of Hazelcast IMDG v4.2.2. I have enabled multicast in Hazelcast config. My IP for three server's are:
192.168.1.10
192.168.1.25
192.168.34.122
Here two are in same series and one is different. Is this the reason. Or is there any limitation in free edition of Hazelcast as only 2 server's can form the cluster?
There is no limitation in Hazelcast Open Source (free) version. You can create as big a cluster as you want.
Concerning your issue, Multicast should work correctly. If it does not, I would check the following parts:
Try to use static TCP/IP configuration (if it does not work, then it's a connectivity issue, not a discoverability issue).
If TCP/IP works, then the next thing to check is if Multicast packets work in your network (sometimes they may be blocked).
If you still have an issue, could you attach Hazeclast logs?

Cant change the port for jetty

I am running googleappengine on SpringBoot, I want to change the port number from 8080. In springboot docs, you make the change in application.yml
server:
port: 8090,
or application.properties server.port=8090.
For springboot tomcat, this works, but not for springboot jetty, googleappengine.
Actually the above property should have worked irrespective of the server.
Give a try with below method (Spring boot 2.0).
#Bean
public ConfigurableServletWebServerFactory webServerFactory()
{
JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
factory.setPort(9000);
factory.setContextPath("/myapp");
factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
return factory;
}
Refer configure jetty server spring boot

When running a springboot app - using spring 5 - how are apache nio properties configured?

We are running a springboot application using the new reactive features. For downstream calls we are using the new WebClient provided by spring. When we configure the max threads - the configuration is honored. We would like to experiment with additional poller threads or changing some of the timeouts. However the nio specific apache configuration is not honored.
Any help is greatly appreciated!
in application.properties
server.tomcat.max-threads=3 <- this is working
server.tomcat.accept-count=1000 <- this is working
server.tomcat.poller-thread-count=5 <- this is not working/ignored
server.tomcat.poller-thread-priority=5 <- this is not working/ignored
server.tomcat.selector-timeout=2000 <- this is not working/ignored
The Connector that is used by Tomcat , e.g the NIO connector can be configured
by providing your own Customizer :
#Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addConnectorCustomizers(connector ->
((AbstractProtocol) connector.getProtocolHandler()).setMaxConnections(200));
// configure some more properties
return factory;
}
}
You can also read:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-tomcat

How to call external non REST API from a spring cloud micro-service that use eureka to call other internal micro-service?

In our project we use Spring cloud + Eureka as service registry.
When we use the ribbon client to call internal micro-services, all URL are resolved via Eureka ... that's a problem to call external URLs.
As external API are old fashioned usage of Feign doesn't seem to be good choice.
What's the best way to call an external URL from such a service ?
Thanks in advance
Patrice
One way working:
Use two configurations.
Declare your RestTemplate Bean to call external services like this:
#Primary
#Qualifier("withoutEureka")
#Bean
public RestTemplate restTemplate(){
...
}
Inject this reference in your client this way
#Bean
public MyClientForExtCall myClientForExtCall(#Qualifier("withoutEureka")RestTemplate restTemplate)
In the other configuration use the restTemplate as usual, but don't forget to use another qualifier
#LoadBalanced
#Bean
#Qualifier("withEureka")
public RestTemplate loadBalancedEureka(){
...
}
#Bean
public MyClientForInternal myClientForInternal(#Qualifier("withoutEureka")RestTemplate restTemplate)
Patrice
You can use Ribbon without Eureka. For external APIs where you cannot configure in Eureka to abstract the discover. You can hard code their URLs in client and configure server list. The Ribbon client defaults to a configured server list, and you can supply the configuration like this:
stores:
ribbon:
listOfServers: example.com, google.com

Resources