Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rabbitTemplate receive() does not dequeue message #303

Open
lz000 opened this issue Jul 5, 2022 · 1 comment
Open

rabbitTemplate receive() does not dequeue message #303

lz000 opened this issue Jul 5, 2022 · 1 comment

Comments

@lz000
Copy link

lz000 commented Jul 5, 2022

I have this simple test. As you can see, calling rabbitTemplate.receive() did not remove message from the queue, although the same message was received every time I called this method. This issue does not happen if I hook to a real rabbitmq

@TestConfiguration
public class TestConfig {

    @Bean
    @Primary
    ConnectionFactory connectionFactory() {
        return new CachingConnectionFactory(new MockConnectionFactory());
    }

    @Bean
    @Primary
    public RabbitAdmin getTestRabbitAdmin(ConnectionFactory connectionFactory) {
        RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
        rabbitAdmin.setAutoStartup(true);
        return rabbitAdmin;
    }

    @Bean
    @Primary
    public RabbitTemplate getTestRabbitTemplate(ConnectionFactory connectionFactory) {
        return new RabbitTemplate(connectionFactory);
    }
}


@SpringBootTest
@Import(TestConfig.class)
class SampleTest {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RabbitAdmin rabbitAdmin;

    @Test
    void test() throws Exception {
         rabbitTemplate.send("test-exchange", "test-key", new Message("test".getBytes(StandardCharsets.UTF_8)));

        Thread.sleep(500);
        QueueInformation info0 = rabbitAdmin.getQueueInfo("test-queue");  // QueueInformation [name=test-queue, messageCount=1, consumerCount=0]

        Message message1 = rabbitTemplate.receive("test-queue", -1);
        Thread.sleep(500);
        QueueInformation info1 = rabbitAdmin.getQueueInfo("test-queue");  // QueueInformation [name=test-queue, messageCount=1, consumerCount=1]

        Message message2 = rabbitTemplate.receive("test-queue", -1);
        Thread.sleep(500);
        QueueInformation info2 = rabbitAdmin.getQueueInfo("test-queue");  // QueueInformation [name=test-queue, messageCount=1, consumerCount=1]
    }
}
@Hatzen
Copy link

Hatzen commented May 22, 2023

I am facing the same issue which is quite unexpected i would say.
Is there any documentation that i am missing?

Hatzen added a commit to Hatzen/rabbitmq-mock that referenced this issue May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants