gpt4 book ai didi

java - 未定义的方法类型

转载 作者:行者123 更新时间:2023-11-30 06:08:10 24 4
gpt4 key购买 nike

我想尽可能地缩减这个 Java 代码:

Consumer consumerone = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
processobjone(body);
}
};
channel.basicConsume(QUEUE_FIRST_NAME, true, consumerone);

Consumer consumersec = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
byte[] body) throws IOException {
processobjsec(body);
}
};
channel.basicConsume(QUEUE_SEC_NAME, true, consumersec);

// Processing

private void processobjone(byte[] body) {
// handle obj
}

private void processobjsec(byte[] body) {
// handle obj
}

// .... and many more

我尝试了这种可能的解决方案,但出现多个错误:

import java.util.function.Consumer;

Map<String, Consumer<byte[]>> queueToConsumer = new HashMap<>();
queueToConsumer.put(ElementTypeEnum.QUEUE_TRANSACTION, this::process_transaction);
queueToConsumer.put(ElementTypeEnum.QUEUE_API_ATTEMPT, this::process_api_attempt);

queueToConsumer.forEach((queueName, consumer) -> {
channel.basicConsume(queueName, true, new DefaultConsumer() {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
consumer.accept(body);
}
});
});

private void process_transaction(byte[] vv) {
}

private void process_api_attempt(byte[] vv) {
}

这些是我进行更改时的错误:

The method basicConsume(String, boolean, Consumer) in the type Channel is not applicable for the arguments (String, boolean, new DefaultConsumer(){})

您能建议我如何解决这些问题吗?也许我需要更改用于重定向到正确的 Java 方法的模式?

最佳答案

看起来DefaultConsumer没有导入,导致编译器无法识别

关于java - 未定义的方法类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50834744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com