skip to Main Content

I have the following problem when running this schedule.

@Singleton
public class TaskScheduler {

    private static final Logger LOG = LoggerFactory.getLogger(TaskScheduler.class);

    @Inject
    private BuildLayerJob buildLayerJob;

    @Scheduled(fixedDelay = "30s", initialDelay = "30s")
    public void loadRegistriesDescriptions(){
        try {
            LOG.info("Cargando lista de registries cada 30s.");
            buildLayerJob.getBuildLayer().loadRegistries();
        }
        catch(Exception exception) {
            LOG.error("Error cargando lista de registries cada 30s: " +exception.getMessage());
            //exception.printStackTrace();
        }
    }
}

In the first execution there is no problem, but when the time expires and it is executed again it throws me the following error.

20:26:59.291 [pool-1-thread-6] ERROR i.m.s.DefaultTaskExceptionHandler - Error invoking scheduled task Error instantiating bean of type  [io.micronaut.configuration.lettuce.health.RedisHealthIndicator]

    Message: Unable to connect to localhost:6379
    Path Taken: new HealthMonitorTask(CurrentHealthStatus currentHealthStatus,[List healthIndicators]) --> new RedisHealthIndicator(BeanContext beanContext,HealthAggregator healthAggregator,[StatefulRedisConnection[] connections])
    io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.configuration.lettuce.health.RedisHealthIndicator]
    
    Message: Unable to connect to localhost:6379
    Path Taken: new HealthMonitorTask(CurrentHealthStatus currentHealthStatus,[List healthIndicators]) --> new RedisHealthIndicator(BeanContext beanContext,HealthAggregator healthAggregator,[StatefulRedisConnection[] connections])
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1719)
        at io.micronaut.context.DefaultBeanContext.addCandidateToList(DefaultBeanContext.java:2727)
        at io.micronaut.context.DefaultBeanContext.getBeansOfTypeInternal(DefaultBeanContext.java:2639)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:924)
        at io.micronaut.context.AbstractBeanDefinition.lambda$getBeansOfTypeForConstructorArgument$9(AbstractBeanDefinition.java:1124)
        at io.micronaut.context.AbstractBeanDefinition.resolveBeanWithGenericsFromConstructorArgument(AbstractBeanDefinition.java:1762)
        at io.micronaut.context.AbstractBeanDefinition.getBeansOfTypeForConstructorArgument(AbstractBeanDefinition.java:1119)
        at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
        at io.micronaut.configuration.lettuce.health.$RedisHealthIndicatorDefinition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1693)
        at io.micronaut.context.DefaultBeanContext.addCandidateToList(DefaultBeanContext.java:2727)
        at io.micronaut.context.DefaultBeanContext.getBeansOfTypeInternal(DefaultBeanContext.java:2639)
        at io.micronaut.context.DefaultBeanContext.getBeansOfType(DefaultBeanContext.java:924)
        at io.micronaut.context.AbstractBeanDefinition.lambda$getBeansOfTypeForConstructorArgument$9(AbstractBeanDefinition.java:1124)
        at io.micronaut.context.AbstractBeanDefinition.resolveBeanWithGenericsFromConstructorArgument(AbstractBeanDefinition.java:1762)
        at io.micronaut.context.AbstractBeanDefinition.getBeansOfTypeForConstructorArgument(AbstractBeanDefinition.java:1119)
        at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:984)
        at io.micronaut.management.health.monitor.$HealthMonitorTaskDefinition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1693)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2407)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2393)
        at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2084)
        at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2058)
        at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:618)
        at io.micronaut.scheduling.processor.ScheduledMethodProcessor.lambda$process$5(ScheduledMethodProcessor.java:123)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:305)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
        at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
        at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
        at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)
        at io.lettuce.core.RedisClient.connect(RedisClient.java:207)
        at io.lettuce.core.RedisClient.connect(RedisClient.java:192)
        at io.micronaut.configuration.lettuce.AbstractRedisClientFactory.redisConnection(AbstractRedisClientFactory.java:51)
        at io.micronaut.configuration.lettuce.DefaultRedisClientFactory.redisConnection(DefaultRedisClientFactory.java:52)
        at io.micronaut.configuration.lettuce.$DefaultRedisClientFactory$RedisConnection1Definition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1693)
        ... 31 common frames omitted
    Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6379
    Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779)
        at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
        at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:702)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)

I understand that there are problems with the connection to redis, but in the microservice deployed in GCP it continues to generate the same problem.

app.yaml

runtime:    java11
service:    default
instance_class: B2

env_variables:
  LAYERS_SERVER_PORT: 8080
  REDIS_FIXEDDELAY: 1s
  REDISA_URL: "redis://A"
  REDISB_URL: "redis://B"
  REDISC_URL: "redis://C"
  REDISD_URL: "redis://D"

basic_scaling:
  max_instances: 1
  idle_timeout: 270s
vpc_access_connector:
  name: "projects/example/locations/us-central1/connectors/example"

Local settings. application.yml:

micronaut:
  application:
    name: example
  server:
    port: ${EXAMPLE_SERVER_PORT:3000}
    cors:
      enabled: true
---
redis:
  servers:
    REDISA:
      uri: redis://IP_A
    REDISB:
      uri: redis://IP_B
    REDISC:
      uri: redis://IP_C
    REDISD:
      uri: redis://IP_D

Repository layers.server.repo.InfoRepositoryImpl:

@Singleton
public class InfoRepositoryImpl implements InfoRepository {

    private BuildLayerJob buildLayerJob;

    @Inject @Named("REDISB")  RedisAsyncCommands<String, String> reddisConnectionB;
    @Inject @Named("REDISA")  RedisAsyncCommands<String, String> reddisConnectionA;

private static final Logger LOG = LoggerFactory.getLogger(InfoRepositoryImpl.class);

    public InfoRepositoryImpl(BuildLayerJob buildLayerJob) {
        this.buildLayerJob = buildLayerJob;
    }

... implementation of methods to process information with redis

 }

2

Answers


  1. Such errors can occur when the said data source is autoconfigured. You can disable Redis autoconfiguration if you’re not using it in the application. If you need Redis for the application then you should set spring.redis.host and spring.redis.port.

    Login or Signup to reply.
  2. Can you please check if you are having io.micronaut.redis:micronaut-redis-lettuce dependency added to your class path/ build file.

    By default Micronaut will assume redis server to be at localhost:6379, as health checks are by default enabled when redis-lettuce is being activated. It will keep probing for health checks.

    If you are using micronaut application.yml, you need to provide the server url which will be accessible from the running app.

    Micronaut redis

    Example – application.yml

    redis:
        uri: redis://localhost
        ssl: true
        timeout: 30s
    

    You can also use below connection string pattern to provide details about redis server.

    Redis Standalone

    redis :// [[username :] password@] host [: port] [/ database][?
    [timeout=timeout[d|h|m|s|ms|us|ns]] [&_database=database_]]

    Redis Standalone (SSL)

    rediss :// [[username :] password@] host [: port] [/ database][?
    [timeout=timeout[d|h|m|s|ms|us|ns]] [&_database=database_]]

    Redis Standalone (Unix Domain Sockets)

    redis-socket :// [[username :] password@]path
    [?[timeout=timeout[d|h|m|s|ms|us|ns]][&_database=database_]]

    for more details on connection string – Redis connections string

    Micronaut redis configuration properties

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search