Java 未定义的方法类型

Java 未定义的方法类型,java,rabbitmq,Java,Rabbitmq,我希望尽可能地缩减此Java代码: Consumer consumerone = new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { process

我希望尽可能地缩减此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) {       
}

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

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

请检查规范以创建Consumer方法以及BasicConsumeth的api。这是我自己的示例。规格不相关。你能提出一些解决方案吗?我主要改进了代码的格式以使其更具可读性。谢谢,但是你能为这个问题提出一些解决方案吗?你能尝试导入DefaultConsumer吗
The method basicConsume(String, boolean, Consumer) in the type Channel is not applicable for the arguments (String, boolean, new DefaultConsumer(){})