Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,12 @@ public static final class Stream {
*/
private int port = DEFAULT_STREAM_PORT;

/**
* Virtual host of a RabbitMQ instance with the Stream plugin enabled. When not
* set, spring.rabbitmq.virtual-host is used.
*/
private String virtualHost;

/**
* Login user to authenticate to the broker. When not set,
* spring.rabbitmq.username is used.
Expand Down Expand Up @@ -1239,6 +1245,14 @@ public void setPort(int port) {
this.port = port;
}

public String getVirtualHost() {
return this.virtualHost;
}

public void setVirtualHost(String virtualHost) {
this.virtualHost = virtualHost;
}

public String getUsername() {
return this.username;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ static EnvironmentBuilder configure(EnvironmentBuilder builder, RabbitProperties
PropertyMapper map = PropertyMapper.get();
map.from(stream.getHost()).to(builder::host);
map.from(stream.getPort()).to(builder::port);
map.from(stream.getVirtualHost())
.as(withFallback(properties::getVirtualHost))
.whenNonNull()
.to(builder::virtualHost);
map.from(stream.getUsername()).as(withFallback(properties::getUsername)).whenNonNull().to(builder::username);
map.from(stream.getPassword()).as(withFallback(properties::getPassword)).whenNonNull().to(builder::password);
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ void whenStreamHostIsSetThenEnvironmentUsesCustomHost() {
then(builder).should().host("stream.rabbit.example.com");
}

@Test
void whenStreamVirtualHostIsSetThenEnvironmentUsesCustomVirtualHost() {
EnvironmentBuilder builder = mock(EnvironmentBuilder.class);
RabbitProperties properties = new RabbitProperties();
properties.getStream().setVirtualHost("stream-virtual-host");
RabbitStreamConfiguration.configure(builder, properties);
then(builder).should().virtualHost("stream-virtual-host");
}

@Test
void whenStreamVirtualHostIsNotSetButDefaultVirtualHostIsSetThenEnvironmentUsesDefaultVirtualHost() {
EnvironmentBuilder builder = mock(EnvironmentBuilder.class);
RabbitProperties properties = new RabbitProperties();
properties.setVirtualHost("default-virtual-host");
RabbitStreamConfiguration.configure(builder, properties);
then(builder).should().virtualHost("default-virtual-host");
}

@Test
void whenStreamCredentialsAreNotSetThenEnvironmentUsesRabbitCredentials() {
EnvironmentBuilder builder = mock(EnvironmentBuilder.class);
Expand Down