Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Redis consumer #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Redis consumer #31

wants to merge 2 commits into from

Conversation

sobychacko
Copy link
Contributor

No description provided.

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.9.1</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I wonder if Spring Boot should manage the version for us...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for info: https://github.com/testcontainers/testcontainers-spring-boot.

If you are interested in we could use their Embedded Redis feature over here: https://github.com/testcontainers/testcontainers-spring-boot#embedded-redis

Probably then we won't need to worry about stopping that Redis server in the test...

/**
* A SpEL expression to use for topic.
*/
private Expression topicExpression;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have bumped recently an issue that Spring Boot configuration properties binding doesn't support Expression by default.
We can accept them only as strings and parse to Expression manually in the configuration class.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stream provides conversion of String to SpEL

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpelExpressionConverterConfiguration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we are in the function library, we can't have a SCSt dependency over here.
We probably can extract that code into a common utility jar, but we would still need to declare a bean for that @ConfigurationPropertiesBinding...

So, probably less error-prone solution would be with a manual SpEL parsing.

static {
GenericContainer redis = new GenericContainer("redis:3-alpine")
.withExposedPorts(6379);
redis.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You start it here. Where do you stop then?

@@ -49,7 +54,8 @@ public MessageHandler redisConsumerMessageHandler(RedisConnectionFactory redisCo
if (redisConsumerProperties.isKeyPresent()) {
RedisStoreWritingMessageHandler redisStoreWritingMessageHandler = new RedisStoreWritingMessageHandler(
redisConnectionFactory);
redisStoreWritingMessageHandler.setKeyExpression(redisConsumerProperties.keyExpression());
redisStoreWritingMessageHandler.setKeyExpression(
new LiteralExpression(redisConsumerProperties.keyExpression()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. It has to be parsed - it is not a plain literal.

Anyway consider a convenient setKeyExpressionString() instead.

return redisStoreWritingMessageHandler;
}
else if (redisConsumerProperties.isQueuePresent()) {
return new RedisQueueOutboundChannelAdapter(redisConsumerProperties.queueExpression(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have missed to parse an expression here.

@SpringBootTest(properties = {"spring.redis.host=${embedded.redis.host}",
"spring.redis.port=${embedded.redis.port}",
"spring.redis.user=${embedded.redis.user}",
"spring.redis.password=${embedded.redis.password}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to move all of these embedded properties into an application.properties in the test/resources!

private RedisConnectionFactory redisConnectionFactory;

@Test
public void testWithKey() throws Exception{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we need more tests to cover all the possible behavior of the consumer.

If we would have them at the first place, we wouldn't talk about expressions now 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants