spring data solr , set timezone UTC - spring-data-solr

all the data in solr are in UTC, my spring boot app is running on a EST JVM ( Tomcat).
Is there is a way to configure solrClient/ SolrTemplat to use UTC timezone for Date?
thanks

Try setting this in you spring boot app file
#PostConstruct
public void init(){
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // It will set UTC timezone
}

Related

Apache Ignite - Rest API timestamp format

I have upgraded Ignite 2.7.6 on Java 8 to Ignite 2.13 on Java 11.
In the REST API response the timestamp format has changed.
Locale and all other ENV variables on the host are equal.
Is there a possibility to define the format of the timestamp output in the
Ignite configuration?
Example of timestamp data, difference is in "," after year.
Ignite 2.7.6 Java 8 -> "Sep 18, 2019 12:57:35 PM"
Ignite 2.13 Java 11 -> "Aug 31, 2022, 12:43:44 PM"
The issue is related to the default locale provider change in the Java 9+, see JEP 252.
As a workaround, you can set the next option to enable behavior compatible with Java 8:
-Djava.locale.providers=COMPAT

Is it possible to implement rate limiting with Geode Redis Adapter?

I am trying to use Geode Redis Adapter as my server for Rate Limiting provided by Spring Cloud Gateway. If I use a real Redis Server, everything works perfectly, but with Geode Redis Adapter doesn't.
I am not too sure if this functionality is supported.
I tried to start a [Geode image] (https://hub.docker.com/r/apachegeode/geode/) exposing the default Redis port 6739. Starting the container, I executed using gfsh the following commands:
start server --name=redis --redis-port=6379 --J=-Dgemfireredis.regiontype=PARTITION_PERSISTENT
When I try to access in my local machine by redis-cli -h localhost -p 6379 I can get connected.
My implementation is simple:
application.yaml
- id: rate-limitter
predicates:
- Path=${GUI_CONTEXT_PATH:/rate-limit}
- Host=${APP_HOST:localhost:8080}
filters:
- name: RequestRateLimiter
args:
key-resolver: "#{#remoteAddrKeyResolve}"
redis-rate-limiter:
replenishRate: ${rate.limit.replenishRate:1}
burstCapacity: ${rate.limit.burstCapacity:2}
uri: ${APP_HOST:localhost:8080}
Application.java
#Bean
KeyResolver remoteAddrKeyResolve() {
return exchange -> Mono.just(exchange.getSession().subscribe().toString());
}
When my application is started and I try to access /rate-limit, I expected to connect to redis and my page be displayed.
However, my Spring application keeps trying to access and can't i.l.c.p.ReconnectionHandler: Reconnected to localhost:6379. So, the page is not displayed and keep loading. FIXED in Edit1 below
Problem is I am using RedisRateLimiter and tried to simulate the access with a for loop. Checking the RedisRateLimiter.REMAINING_HEADER, the value is -1 always. Doesn't seems right, because I don't have this issue in Redis itself.
During the start of the application, I also receive these messages on connection to Geode Redis Adapter:
Starting without optional epoll library
Starting without optional kqueue library
Is anything missing in my Geode Redis Adapter or anything else in Spring?
Thank you
Edit 1: I was missing to start the locator and region, that's why I wasn't able to connect.
start locator --name=locator
start server --name=redis --redis-port=6379 --J=-Dgemfireredis.regiontype=PARTITION_PERSISTENT
create region --name=redis-region --type=REPLICATE_PERSISTENT

Spring Session Redis with Sticky session on server side for log

Hi i have a Redis configured on my Spring project to use Spring Session, i'm using Jedis 2.9.0 and it works well. The problem I have is with the Sticky session on the Websphere Server, we have 2 main servers and 10 clones of each, with normal httpSession it uses the cookie to handle the request of that cookie to the same server again, good, but with Spring Session it doesn't work the same.
Spring create the cookie with the name "SESSION" and the Load Balancing of Websphere doesn't know where to redirect the request because the session is not on the JVM but is ditributed in Redis Cluster.
i need to (for log order porpuse) handle every request of cookie "abc123" to the server 1 clon 3 for example, and if that instance of the application goes down track that cookie to another instance and stay on that instance until the server goes down again or the user logout...
Searching here and the Spring Session doc, i found something that might be useful but I dont know how it works.
#Bean
public CookieSerializer cookieSerializer() {
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
serializer.setCookieName("JSESSIONID");
serializer.setCookiePath("/");
serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
serializer.setJvmRoute("123");
return serializer;
}
The atribute Jvm Route adds a suffix to the cookie to know whats the JVM that handle that cookie, but i don't know how it works and I haven't been lucky finding examples or explanation about it.
if anyone have the answer or another workaround that i could use it will be great.

How to write log from gemfire function

I have a gemfire function which is ment to be deployed in a gemfire cluster. What is the way to write log from function, so that it goes to server log file.
My gemfire version is 8.2.0
You should use either the LogService.getLogger(String) or LogService.getLogger() method to get a Logger instance. The latter is a convenience method and sets the name of the returned Logger to the name of the calling class. The Logger returned by these methods is a log4j Logger.
I actually figured it out. From Gemfire 8.1.0 the log library they use has changed and it now uses Apache Log4j2. Logs done through this logger goes to the server log file.

SignalR initial connection very slow on page refresh (delay on OnDisconnected)

I've been using SignalR for a while in my MVC5 project, but only in the recent weeks I encountered this problem.
Every time I refresh a page or navigate to a different page within my project, it takes a long time (between 3-8 seconds) to establish new connection.
[09:18:12 GMT+0100 (GMT Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:53516/signalr/connect?transport=serverSentEvents&connectio…3A%22notehub%22%7D%2C%7B%22name%22%3A%22retailpriceindexhub%22%7D%5D&tid=6'. jquery.signalR-2.0.3.min.js:8
[09:18:18 GMT+0100 (GMT Daylight Time)] SignalR: EventSource connected.
Although normally I don't use them, I created those override methods for one of my hubs on the server just to see when breakpoints are being hit:
public override Task OnConnected()
{
var connectionId = Context.ConnectionId;
return base.OnConnected();
}
public override Task OnReconnected()
{
var connectionId = Context.ConnectionId;
return base.OnReconnected();
}
public override Task OnDisconnected()
{
var connectionId = Context.ConnectionId;
return base.OnDisconnected();
}
This confirmed that on page refresh OnDisconnected method doesn't get called immediately, but after the delay mentioned above. Once it gets hit, it's followed by OnConnected straight away and everything goes smoothly from that point.
Initially I thought it was similar to: https://github.com/SignalR/SignalR/issues/2719, but:
that was an issue with Chrome (Version 31.0.1650.57); I am on Version
34.0.1847.116 m. my issue affects all browsers (IE being slightly quicker than Chrome or Firefox) according to that issue OnDisconnected was delayed only when navigating to another page in the project - in my case OnDisconnected is not called immediately even when I close the tab or navigate to an external page
When I open a new tab, connection is established immedietaly:
[09:31:26 GMT+0100 (GMT Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:53516/signalr/connect?transport=serverSentEvents&connectio…3A%22notehub%22%7D%2C%7B%22name%22%3A%22retailpriceindexhub%22%7D%5D&tid=6'. jquery.signalR-2.0.3.min.js:8
[09:31:26 GMT+0100 (GMT Daylight Time)] SignalR: EventSource connected.
This proves to me that the delay happens somewhere between $.connection.hub.start() and hitting OnDisconnected method on the server, but I don't know how to trace it down.
I have enabled server side logging by modifying Web.config file, but I can't see anything obvious in the logs.
Also, I have tried changing the transport method to longPolling, but the issue still exists.
Similar issued raised on SignalR github page mentioned AVG or proxy, but none of these are relevant in my case.
I have updated signalR packages (server and client) as well as NewtonSoft.Json to the latest versions to no avail.
The issue has been resolved by changing Ninject scoping for my DbFactory and UnitOfWork bindings. I didn't include that part of code in my question, as I had no idea that's where the issue was.
Originally I was using InRequestScope. After changing to InThreadScope, the issue with slow connection disappeared, however I run into more problems then with DbContext lifecycles.
InCallScope from Ninject.Extensions.NamedScope seems to be ideal for my needs.
Bind<IDbFactory>().To<DbFactory>().InCallScope();
Bind<IUnitOfWork>().To<UnitOfWork>().InCallScope();
If someone can explain why InRequestScope or default InTransientScope had such impact on SignalR performance (initial connection) in my project, I will be happy to accept it as an answer.