Skip to content
Merged
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 @@ -494,8 +494,6 @@ private static String getEntityPath(ClientLogger logger, MessagingEntityType ent
public final class ServiceBusSenderClientBuilder {
private String queueName;
private String topicName;
private String viaQueueName;
private String viaTopicName;

private ServiceBusSenderClientBuilder() {
}
Expand All @@ -512,34 +510,6 @@ public ServiceBusSenderClientBuilder queueName(String queueName) {
return this;
}

/**
* Sets the name of the initial destination Service Bus queue to publish messages to.
*
* @param viaQueueName The initial destination of the message.
*
* @return The modified {@link ServiceBusSenderClientBuilder} object.
* @see <a href="https://docs.microsoft.com/azure/service-bus-messaging/service-bus-transactions#transfers-and-send-via">Send
* Via</a>
*/
public ServiceBusSenderClientBuilder viaQueueName(String viaQueueName) {
this.viaQueueName = viaQueueName;
return this;
}

/**
* Sets the name of the initial destination Service Bus topic to publish messages to.
*
* @param viaTopicName The initial destination of the message.
*
* @return The modified {@link ServiceBusSenderClientBuilder} object.
* @see <a href="https://docs.microsoft.com/azure/service-bus-messaging/service-bus-transactions#transfers-and-send-via">Send
* Via</a>
*/
public ServiceBusSenderClientBuilder viaTopicName(String viaTopicName) {
this.viaTopicName = viaTopicName;
return this;
}

/**
* Sets the name of the Service Bus topic to publish messages to.
*
Expand All @@ -560,25 +530,15 @@ public ServiceBusSenderClientBuilder topicName(String topicName) {
* @throws IllegalStateException if {@link #queueName(String) queueName} or {@link #topicName(String)
* topicName} are not set or, both of these fields are set. It is also thrown if the Service Bus {@link
* #connectionString(String) connectionString} contains an {@code EntityPath} that does not match one set in
* {@link #queueName(String) queueName} or {@link #topicName(String) topicName}. Or the {@link
* #viaQueueName(String) viaQueueName} is specified along with {@link #topicName(String) topicName}.
* {@link #queueName(String) queueName} or {@link #topicName(String) topicName}.
* @throws IllegalArgumentException if the entity type is not a queue or a topic.
*/
public ServiceBusSenderAsyncClient buildAsyncClient() {
final ServiceBusConnectionProcessor connectionProcessor = getOrCreateConnectionProcessor(messageSerializer);
final MessagingEntityType entityType = validateEntityPaths(logger, connectionStringEntityName, topicName,
queueName);

if (!CoreUtils.isNullOrEmpty(viaQueueName) && entityType == MessagingEntityType.SUBSCRIPTION) {
throw logger.logExceptionAsError(new IllegalStateException(String.format(
"(%s), Via queue feature work only with a queue.", viaQueueName)));
} else if (!CoreUtils.isNullOrEmpty(viaTopicName) && entityType == MessagingEntityType.QUEUE) {
throw logger.logExceptionAsError(new IllegalStateException(String.format(
"(%s), Via topic feature work only with a topic.", viaTopicName)));
}

final String entityName;
final String viaEntityName = !CoreUtils.isNullOrEmpty(viaQueueName) ? viaQueueName : viaTopicName;
switch (entityType) {
case QUEUE:
entityName = queueName;
Expand All @@ -595,7 +555,7 @@ public ServiceBusSenderAsyncClient buildAsyncClient() {
}

return new ServiceBusSenderAsyncClient(entityName, entityType, connectionProcessor, retryOptions,
tracerProvider, messageSerializer, ServiceBusClientBuilder.this::onClientClose, viaEntityName);
tracerProvider, messageSerializer, ServiceBusClientBuilder.this::onClientClose, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,66 +52,6 @@ class ServiceBusClientBuilderTest {
ENDPOINT, SHARED_ACCESS_KEY_NAME, SHARED_ACCESS_KEY, QUEUE_NAME);
private static final Proxy PROXY_ADDRESS = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, Integer.parseInt(PROXY_PORT)));

@Test
void viaQueueNameWithTopicNotAllowed() {
// Arrange
ServiceBusSenderClientBuilder builder = new ServiceBusClientBuilder()
.connectionString(NAMESPACE_CONNECTION_STRING)
.sender()
.topicName(TOPIC_NAME)
.viaQueueName(VIA_QUEUE_NAME);

// Act & Assert
assertThrows(IllegalStateException.class, () -> builder.buildAsyncClient());
}

@Test
void viaTopicNameWithQueueNotAllowed() {
// Arrange
ServiceBusSenderClientBuilder builder = new ServiceBusClientBuilder()
.connectionString(NAMESPACE_CONNECTION_STRING)
.sender()
.queueName(QUEUE_NAME)
.viaTopicName(VIA_TOPIC_NAME);

// Act & Assert
assertThrows(IllegalStateException.class, () -> builder.buildAsyncClient());
}

@Test
void queueClientWithViaQueueName() {
// Arrange
final ServiceBusSenderClientBuilder builder = new ServiceBusClientBuilder()
.connectionString(NAMESPACE_CONNECTION_STRING)
.sender()
.queueName(QUEUE_NAME)
.viaQueueName(VIA_QUEUE_NAME);

// Act
final ServiceBusSenderAsyncClient client = builder.buildAsyncClient();

// Assert
assertNotNull(client);
assertEquals(client.getEntityPath(), QUEUE_NAME);
}

@Test
void topicClientWithViaTopicName() {
// Arrange
final ServiceBusSenderClientBuilder builder = new ServiceBusClientBuilder()
.connectionString(NAMESPACE_CONNECTION_STRING)
.sender()
.topicName(TOPIC_NAME)
.viaTopicName(VIA_TOPIC_NAME);

// Act
final ServiceBusSenderAsyncClient client = builder.buildAsyncClient();

// Assert
assertNotNull(client);
assertEquals(client.getEntityPath(), TOPIC_NAME);
}

@Test
void deadLetterqueueClient() {
// Arrange
Expand Down
Loading