如何以声明方式为自主NServiceBus预安装特定队列

时间:2014-09-03 14:07:32

标签: nservicebus

我正在使用NSB 4.6.4。我知道我可以在自我主机进程中使用以下代码来专门为我的配置创建必要的队列和Raven DB文档:

Configure.With()
.UnicastBus()
.CreateBus()
.Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());

但是有没有办法在我的进程运行之前预先安装这些,以声明的方式单独进行(不运行代码)?

2 个答案:

答案 0 :(得分:0)

您可以使用PowerShell执行此操作,请查看managing NserviceBus using PowerShell article

答案 1 :(得分:0)

根据Sean的最后评论,这是我使用的powershell脚本:

[Reflection.Assembly]::LoadWithPArtialName("System.Messaging")
$msmq = [System.Messaging.MessageQueue]
$userName = "Users"
$baseQueueName = ".\private$\myQueueName"
$mainQueue = $baseQueueName
$retryQueue = $baseQueueName + ".retries"
$timeoutQueue = $baseQueueName + ".timeouts"
$timeOutDispatcherQueue = $baseQueueName + ".timeoutsDispatcher"
$nameArray = $mainQueue, $retryQueue, $timeoutQueue, $timeoutDispatcherQueue
for ($i=0; $i -lt $nameArray.length; $i++) 
{ 
If ($msmq::Exists($nameArray[$i]))
{
Echo ($nameArray[$i] + " queue already exists . . . skipping.")
}
else
{
Echo ("Creating queue '" + $nameArray[$i] + "'.")
# second argument of 1 indicates Transactional Queue
$qObject = $msmq::Create($nameArray[$i], 1) 
}

Echo ("Adding Permissions for '" + $userName + "' to queue '" + $nameArray[$i] + ".")

$q2 = New-Object System.Messaging.MessageQueue $nameArray[$i]
$q2.SetPermissions($userName, 
[System.Messaging.MessageQueueAccessRights]::FullControl, 
[System.Messaging.AccessControlEntryType]::Set) 
}