小编Swa*_*nil的帖子

Resilience4j - 请求超时

我有一个使用 Hystrix断路器模式的服务,它调用第 3 方服务。在...的帮助下

@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
Run Code Online (Sandbox Code Playgroud)

我已经定义了第 3 方服务的超时。

由于 Hystrix 处于维护模式,因此我正在从 Hystrix 迁移到 Resilience4j 断路器模式。如何在 resiience4j 中实现类似的超时处理。

我知道可以通过使用注释来实现类似的事情,注释是resilience4j-timeLimiter@TimeLimiter库的一部分。但根据这个问题,我必须将方法的返回类型修改为. 这将涉及对我现有服务的大量代码更改。CompletableFuture

如何使用 Resilience4j 实现这一目标?

java circuit-breaker spring-boot resilience4j

8
推荐指数
1
解决办法
1万
查看次数

dotenv 同一环境的多个文件

我试图在同一环境中使用多个配置文件。到目前为止,我正在为一个配置文件执行此操作:

node -r dotenv/config index.js dotenv_config_path=/etc/secrets/env.txt
Run Code Online (Sandbox Code Playgroud)

但是,现在我有一个要求,我必须读取同一环境的多个配置文件。

为了实现这一目标,我尝试了这个命令。它仅从第一个文件加载配置。

node -r dotenv/config index.js dotenv_config_path=/etc/secrets/env1.txt /etc/secrets/env2.txt
Run Code Online (Sandbox Code Playgroud)

这个可以实现吗?TIA。

javascript node.js dotenv

5
推荐指数
1
解决办法
1144
查看次数

Redis - 错误:值不是有效的浮点数

我在 Redis 中有一个排序集。我正在尝试通过在 Python 代码中使用 Zincrby 来更新特定元素的计数器值,例如:

conn.zincrby("usersSet", float(1), "user1")
Run Code Online (Sandbox Code Playgroud)

但它显示的错误为:“错误:值不是有效的浮点数”

我在 cli 上尝试了相同的命令:zincrby usersSet 1 users1 并且它工作正常。Python 代码中是否还有其他方法可以增加排序集中特定键的计数器值。

python redis python-2.7

4
推荐指数
1
解决办法
4527
查看次数

在烧瓶中请求授权

我正在开发一个 Flask 应用程序,它调用在 Flask 中开发的 REST 服务。目标 REST 服务方法使用基本身份验证进行保护。我发现对于这种类型的身份验证,我必须使用 base64 编码。我正在尝试以这种方式将凭据传递给服务:

headers = {'username': base64.b64encode(g.user['username'])}
response = requests.post('http://127.0.0.1:3000/api/v1.0/follower/' + username, headers=headers)
Run Code Online (Sandbox Code Playgroud)

在服务端,用户名被提取为:

user_name = request.authorization.username
Run Code Online (Sandbox Code Playgroud)

但是,该服务无法对提供的凭据进行授权,并且会引发错误 401。服务端和应用程序端的授权是否存在任何问题?

python werkzeug flask python-2.7

3
推荐指数
1
解决办法
7683
查看次数

kubectl 部署失败

我正在为 GKE 上的 Spring 启动应用程序设置 CI CD 管道。CI 构建步骤工作正常,但交付构建步骤由于“错误:没有传递给应用的对象”错误而失败。我可以在云构建中看到以下日志

Starting Step #0 - "Deploy"
Step #0 - "Deploy": Already have image (with digest): gcr.io/cloud-builders/kubectl
Step #0 - "Deploy": Running: gcloud container clusters get-credentials --project="location-finder-kubernetes" --zone="us-central1-b" "location-finder"
Step #0 - "Deploy": Fetching cluster endpoint and auth data.
Step #0 - "Deploy": kubeconfig entry generated for location-finder.
Step #0 - "Deploy": Running: kubectl apply -f kubernetes.yaml
Step #0 - "Deploy": error: no objects passed to apply
Finished Step #0 - "Deploy"
ERROR …
Run Code Online (Sandbox Code Playgroud)

kubernetes kubectl

2
推荐指数
2
解决办法
4719
查看次数

Spring云流(Kafka)autoCreateTopics不工作

我正在将 Spring Cloud Stream 与 Kafka Binder 一起使用。要禁用自动创建主题,我参考了此内容 - How can I configure a Spring Cloud Stream (Kafka) application to autocreate the topic in Confluence Cloud? 。但是,似乎设置此属性不起作用,框架会自动创建主题。

这是application.properties中的配置

spring.cloud.stream.kafka.binder.auto-create-topics=false
Run Code Online (Sandbox Code Playgroud)

这是启动日志

2021-06-25 09:22:46.522  INFO 38879 --- [pool-2-thread-1] o.a.k.clients.consumer.ConsumerConfig    : ConsumerConfig values: 
    allow.auto.create.topics = true
    auto.commit.interval.ms = 5000
    auto.offset.reset = latest
    bootstrap.servers = [localhost:9092]
Run Code Online (Sandbox Code Playgroud)

其他详情-

  1. Spring启动版本:2.3.12.RELEASE
  2. Spring Cloud Stream版本:Hoxton.SR11

我在这个配置中遗漏了什么吗?

spring apache-kafka spring-cloud-stream spring-cloud-stream-binder-kafka

2
推荐指数
1
解决办法
2389
查看次数

react-bootstrap 手风琴未加载

我正在尝试在 Bootstrap 5 中使用 react-bootstrap。我想在我的一个页面中使用 Accordion。为此,我只是从这个页面复制了结构-> https://react-bootstrap.netlify.app/components/accordion/。但是当我打开页面时,浏览器显示此错误-

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of `Questions`.
Run Code Online (Sandbox Code Playgroud)

这是我使用这个组件的代码

import Accordion from 'react-bootstrap/Accordion';

const Questions = () => (
    <Accordion defaultActiveKey="0" flush>
        <Accordion.Item eventKey="0">
            <Accordion.Header>Question #1</Accordion.Header>
            <Accordion.Body>
                Answer to the Question …
Run Code Online (Sandbox Code Playgroud)

reactjs react-bootstrap bootstrap-5

2
推荐指数
1
解决办法
448
查看次数

Springboot Kafka - 消费者幂等性

我有一个监听 kafka 的 Spring-boot 应用程序。为了避免重复处理,我尝试进行手动提交。为此,我在阅读主题后立即引用了异步提交消息。但我陷入了如何实现消费者幂等性的困境,这样记录就不会被处理两次。

apache-kafka spring-boot spring-kafka

1
推荐指数
1
解决办法
2063
查看次数

Jest 模拟 MongoDB 的嵌套函数

我有一个管理 MongoDB 客户端方法的帮助程序类。

class Common {
   constructor() {
        this._client = null;
   }
   
   static async connect(url) {
        this._client = await MongoClient.connect(url, {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        });
        return this._client;
    }

    static async getCollection({ url, db_name, collection_name }) {
        const client = await Common.connect(url);

        return client.db(db_name).collection(collection_name);
    }
   
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试为 getCollection 方法编写测试用例。这就是我尝试过的

jest.mock('mongodb');
it('To check if the collection method on the MongoClient instance was invoked', () => {
    Common.getCollection({});

    const mockMongoClientInstance = MongoClient.mock.instances[0];
    const mockMongoDBConnect = mockMongoClientInstance.connect;
    expect(mockMongoDBConnect).toHaveBeenCalledTimes(1);
});
Run Code Online (Sandbox Code Playgroud)

显然,这个测试用例覆盖了getCollection方法的第一行,并且测试用例实际上尝试执行第二行。我如何模拟第二行?任何建议都会有帮助。提前致谢。

mocking mongodb node.js jestjs

1
推荐指数
1
解决办法
4449
查看次数

ScheduledExecutorService 具有最小和最大线程数

我正在尝试使用 ScheduledExecutorService 在给定线程池上安排任务。

public ScheduledExecutorService scheduledExecutorService() {
    return Executors.newScheduledThreadPool(3);
}
Run Code Online (Sandbox Code Playgroud)

看起来这种创建实例的方式假定用户指定的值作为最小线程数,最大线程数为Integer.MAX_VALUE(默认值)。

如何指定 ScheduledExecutorService 实例的最大线程数?我无法分配如此巨大的线程数作为最大线程数。

反编译 jar 中的代码片段 -

// From Executors.java
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
    return new ScheduledThreadPoolExecutor(corePoolSize);
}

// From ScheduledThreadPoolExecutor.java
public ScheduledThreadPoolExecutor(int corePoolSize) {
    super(corePoolSize, Integer.MAX_VALUE,
          DEFAULT_KEEPALIVE_MILLIS, MILLISECONDS,
          new DelayedWorkQueue());
}

// From ThreadPoolExecutor.java
public ThreadPoolExecutor(int corePoolSize,
                          int maximumPoolSize,
                          long keepAliveTime,
                          TimeUnit unit,
                          BlockingQueue<Runnable> workQueue) {
    this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
         Executors.defaultThreadFactory(), defaultHandler);
}
Run Code Online (Sandbox Code Playgroud)

如果我缺少引用 Java 文档中的方法,请指出正确的位置。TIA。

java multithreading

1
推荐指数
1
解决办法
1678
查看次数

Python:在Sqlite3中插入UUID值

我正在尝试将 UUID 值插入到 sqlite3 数据库中

INSERT INTO user (user_id,username, email) VALUES (uuid.UUID('7005d0e0-f25b-45f9-897d-bae151fddaff'),'user', 'user@gmail.com')
Run Code Online (Sandbox Code Playgroud)

我将 UUID 值作为自定义数据类型“GUID”存储在数据库中。对于此转换,我使用 sqlite3 转换器作为

sqlite3.register_converter('GUID', lambda b: uuid.UUID(bytes_le=b))
Run Code Online (Sandbox Code Playgroud)

此查询的问题,查询执行失败,因为:

sqlite3.OperationalError: near "(": syntax error
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?我想将 UUID 值存储到数据库中。

python sqlite

0
推荐指数
1
解决办法
2864
查看次数