简体   繁体   English

Java Lambda 中的 Reddison 客户端不工作(使用 samLocal 和 localstack)

[英]Not working Reddison client in Java Lambda(using samLocal and localstack)

I'm not sure what's causing this to not work.我不确定是什么导致这不起作用。 Everytime the code hits the initialization of the client, it stop working Is using Redisson not viable in a Lambda setup?每次代码遇到客户端的初始化时,它都会停止工作在 Lambda 设置中使用 Redisson 不可行吗?

Main code for initializing redisson client:初始化 redisson 客户端的主要代码

public boolean itemExistInCache(String item) {
    Config config = new Config();
    config.useSingleServer().setAddress("127.0.0.1:6379");

    // this one is not working
    RedissonClient redissonClient = Redisson.create(config);
}

Setup设置

  • The Lambda containing the code above is triggered everytime there is a message registered in the SQS.每次在 SQS 中注册一条消息时,都会触发包含上述代码的 Lambda。 The SQS message is subscribed to an SNS Topic. SQS 消息订阅了一个 SNS 主题。

  • SNS + SQS setup is created/initialized with localstack使用 localstack 创建/初始化 SNS + SQS 设置

  • Lambda runs with aws sam local (pip3 install --user aws-sam-cli) Lambda 使用 aws sam local 运行(pip3 install --user aws-sam-cli)

What I've tried and working so far到目前为止我已经尝试过和工作过的

  • using Jedis jedis = new Jedis() //using the same redis "localhost: 6379" using Jedis jedis = new Jedis() //使用相同的redis "localhost: 6379"

If you intend on running this code in a 'real' lambda (vs sam-local) you will need to run the lambda within a VPC, in which case it will have no external networking unless you setup a NAT or similar in your VPC.如果您打算在“真实” lambda(与 sam-local)中运行此代码,则需要在 VPC 中运行 lambda,在这种情况下,除非您在 VPC 中设置 NAT 或类似网络,否则它将没有外部网络。
If in sam-local your using 127.0.0.1 -- are you sure your 'lambda' running in sam-local is not in a network cgroup (such as running in docker - if in docker its likely that 'localhost' is not where redis lives ) ?如果在 sam-local 中您使用 127.0.0.1 - 您确定在 sam-local 中运行的 'lambda' 不在网络 cgroup 中(例如在 docker 中运行 - 如果在 docker 中很可能 'localhost' 不在 redis 中)活着)? This question/problem is almost certainly an issue about network connectivity and port mapping within sam-local.这个问题几乎可以肯定是关于 sam-local 中的网络连接和端口映射的问题。 You can validate this by trying something other then reddison to try to connect to the endpoint to see if it connects at all -- a URL.openStream() should at least connect enough to give an error.您可以通过尝试除 reddison 之外的其他方法尝试连接到端点以查看它是否完全连接来验证这一点——URL.openStream() 至少应该连接到足以给出错误的程度。 (redis is not HTTP so it wont 'work' but it will connect vs hang -- hangs are almost always related to IP or Port isolation) (redis 不是 HTTP,所以它不会“工作”,但它会连接 vs 挂起——挂起几乎总是与 IP 或端口隔离有关)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM