Skip to content

Commit 733e34b

Browse files
committed
Allow submission to different queue/topic
1 parent 72ca3e2 commit 733e34b

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

ServiceBusToolset/Commands/ResubmitDlqCommand.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ private async Task<int> ExecuteResubmitAsync(
145145
string entityDescription,
146146
CancellationToken cancellationToken)
147147
{
148-
Output.Info($"Resubmitting DLQ messages for {entityDescription}...");
148+
var targetInfo = GetTargetInfo(options);
149+
Output.Info($"Resubmitting DLQ messages for {entityDescription}{targetInfo}...");
149150

150151
if (options.BeforeEnqueueTime.HasValue)
151152
{
@@ -166,8 +167,9 @@ private async Task<int> ExecuteFullResubmitAsync(
166167
options.Topic,
167168
options.Subscription,
168169
ServiceBusReceiveMode.PeekLock);
169-
await using var sender = CreateSender(client, options.Queue, options.Topic);
170+
await using var sender = CreateSender(client, options.EffectiveTarget);
170171

172+
var targetInfo = GetTargetInfo(options);
171173
var totalResubmitted = 0;
172174
var emptyBatches = 0;
173175

@@ -196,7 +198,7 @@ private async Task<int> ExecuteFullResubmitAsync(
196198
}
197199

198200
Console.WriteLine();
199-
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription}");
201+
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription}{targetInfo}");
200202
return 0;
201203
}
202204

@@ -211,8 +213,9 @@ private async Task<int> ExecuteFilteredResubmitAsync(
211213
options.Topic,
212214
options.Subscription,
213215
ServiceBusReceiveMode.PeekLock);
214-
await using var sender = CreateSender(client, options.Queue, options.Topic);
216+
await using var sender = CreateSender(client, options.EffectiveTarget);
215217

218+
var targetInfo = GetTargetInfo(options);
216219
var totalResubmitted = 0;
217220
var totalSkipped = 0;
218221
var emptyBatches = 0;
@@ -267,7 +270,7 @@ private async Task<int> ExecuteFilteredResubmitAsync(
267270
}
268271

269272
Console.WriteLine();
270-
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription} (skipped {totalSkipped} newer messages)");
273+
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription}{targetInfo} (skipped {totalSkipped} newer messages)");
271274
return 0;
272275
}
273276

@@ -320,12 +323,13 @@ private async Task<int> ExecuteInteractiveResubmitAsync(
320323
totalToResubmit += cat.Count;
321324
}
322325

323-
Output.Info($"Resubmitting {totalToResubmit} messages from {selectedIndices.Count} categories...");
326+
var targetInfo = GetTargetInfo(options);
327+
Output.Info($"Resubmitting {totalToResubmit} messages from {selectedIndices.Count} categories{targetInfo}...");
324328

325329
var totalResubmitted = await ResubmitByCategoriesAsync(client, options, selectedCategories, cancellationToken);
326330

327331
Console.WriteLine();
328-
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription}.");
332+
Output.Success($"Resubmitted {totalResubmitted} messages from DLQ for {entityDescription}{targetInfo}.");
329333
return 0;
330334
}
331335

@@ -414,7 +418,7 @@ private async Task<int> ResubmitByCategoriesAsync(
414418
options.Topic,
415419
options.Subscription,
416420
ServiceBusReceiveMode.PeekLock);
417-
await using var sender = CreateSender(client, options.Queue, options.Topic);
421+
await using var sender = CreateSender(client, options.EffectiveTarget);
418422

419423
var totalResubmitted = 0;
420424
var totalSkipped = 0;
@@ -498,5 +502,17 @@ private static ServiceBusMessage CreateResubmitMessage(ServiceBusReceivedMessage
498502
return message;
499503
}
500504

501-
private static ServiceBusSender CreateSender(ServiceBusClient client, string? queueName, string? topicName) => client.CreateSender(!string.IsNullOrEmpty(queueName) ? queueName : topicName!);
505+
private static ServiceBusSender CreateSender(ServiceBusClient client, string targetEntity) => client.CreateSender(targetEntity);
506+
507+
private static string GetTargetInfo(ResubmitDlqOptions options)
508+
{
509+
var hasCustomTarget = !string.IsNullOrEmpty(options.TargetQueue) || !string.IsNullOrEmpty(options.TargetTopic);
510+
if (!hasCustomTarget)
511+
{
512+
return string.Empty;
513+
}
514+
515+
var targetType = !string.IsNullOrEmpty(options.TargetQueue) ? "queue" : "topic";
516+
return $" to {targetType} '{options.EffectiveTarget}'";
517+
}
502518
}

ServiceBusToolset/Options/ResubmitDlqOptions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,21 @@ public class ResubmitDlqOptions
4747
HelpText = "Interactive mode: show categories and select which to resubmit")]
4848
public bool Interactive { get; set; }
4949

50+
[Option("target-queue", HelpText = "Target queue to resubmit messages to (defaults to source queue)")]
51+
public string? TargetQueue { get; set; }
52+
53+
[Option("target-topic", HelpText = "Target topic to resubmit messages to (defaults to source topic)")]
54+
public string? TargetTopic { get; set; }
55+
5056
public bool IsQueueMode => !string.IsNullOrEmpty(Queue);
5157
public bool IsSubscriptionMode => !string.IsNullOrEmpty(Topic) && !string.IsNullOrEmpty(Subscription);
5258

59+
/// <summary>
60+
/// Gets the effective target entity name for resubmission.
61+
/// Returns target-queue/target-topic if specified, otherwise falls back to source queue/topic.
62+
/// </summary>
63+
public string EffectiveTarget => TargetQueue ?? TargetTopic ?? Queue ?? Topic!;
64+
5365
public string? Validate()
5466
{
5567
if (!IsQueueMode && !IsSubscriptionMode)
@@ -67,6 +79,11 @@ public class ResubmitDlqOptions
6779
return "When --subscription is specified, --topic is also required.";
6880
}
6981

82+
if (!string.IsNullOrEmpty(TargetQueue) && !string.IsNullOrEmpty(TargetTopic))
83+
{
84+
return "Cannot specify both --target-queue and --target-topic.";
85+
}
86+
7087
return null;
7188
}
7289
}

docs/resubmit-dlq.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dotnet run -- resubmit-dlq -n <namespace> (-q <queue> | -t <topic> -s <subscript
1616
| `--queue` | `-q` | Queue name |
1717
| `--topic` | `-t` | Topic name (requires `--subscription`) |
1818
| `--subscription` | `-s` | Subscription name (requires `--topic`) |
19+
| `--target-queue` | | Target queue to resubmit to (defaults to source queue) |
20+
| `--target-topic` | | Target topic to resubmit to (defaults to source topic) |
1921
| `--before` | | Only resubmit messages enqueued before this UTC datetime (ISO 8601) |
2022
| `--dry-run` | | Preview message count without resubmitting |
2123
| `--interactive` | `-i` | Interactive mode: view and select categories to resubmit |
@@ -26,13 +28,23 @@ dotnet run -- resubmit-dlq -n <namespace> (-q <queue> | -t <topic> -s <subscript
2628
### Resubmit All Messages
2729

2830
```bash
29-
# From a queue DLQ back to the queue
31+
# From a queue DLQ back to the same queue
3032
dotnet run -- resubmit-dlq -n mynamespace.servicebus.windows.net -q myqueue
3133

32-
# From a topic subscription DLQ back to the topic
34+
# From a topic subscription DLQ back to the same topic
3335
dotnet run -- resubmit-dlq -n mynamespace.servicebus.windows.net -t mytopic -s mysub
3436
```
3537

38+
### Resubmit to a Different Destination
39+
40+
```bash
41+
# Resubmit from queue DLQ to a different queue
42+
dotnet run -- resubmit-dlq -n mynamespace.servicebus.windows.net -q myqueue --target-queue other-queue
43+
44+
# Resubmit from subscription DLQ to a different topic
45+
dotnet run -- resubmit-dlq -n mynamespace.servicebus.windows.net -t mytopic -s mysub --target-topic other-topic
46+
```
47+
3648
### Dry Run
3749

3850
Preview message count without resubmitting:

0 commit comments

Comments
 (0)