java - Undefined method type
问题描述
I want to shrink this Java code as much as possible:
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
I tried this possible solution but I get multiple errors:
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) {
}
These are the errors when I made the changes:
The method basicConsume(String, boolean, Consumer) in the type Channel is not applicable for the arguments (String, boolean, new DefaultConsumer(){})
Can you advice how I can solve the issues? Probably I need to change the pattern which is used to redirect to proper Java methods?
解决方案
看起来 DefaultConsumer 没有被导入,导致编译器无法识别它
推荐阅读
- html - 无法在css中应用自定义字体
- java - 哪个对数组列表更有效:collections.swap() 还是使用临时变量进行交换?
- java - Java - 字数对错
- python-3.x - 合并 GDML 文件
- python - pytorch DataLoader 第一个时期极慢
- typescript - 是否可以为多类型参数类/函数的多个参数创建类型别名?
- seaborn - 如何在 seaborn pairplot 中添加细节
- java - 需要有关 Java 中通配符泛型类型的帮助
- spring-boot - Thymeleaf 和 Spring Boot 中的错误处理
- javascript - 使用 jQuery 的 .load() 返回更新 IMG SRC 值