Neden aşağıda belirtilen aşağıdaki işleyici ( processMessageAsync ) belirli bir konu adı için tetiklenmiyor ama diğer konu adları için başarılı anlamıyorum :
subscriptionClient.RegisterMessageHandler(processMessageAsync, msgOptions)
Abone sınıfım şu şekildedir :
open System
open System.Linq
open System.Threading
open System.Text
open System.Threading.Tasks
open Microsoft.Azure.ServiceBus
type Subscriber(connectionString:string, topic:string, subscription:string) =
let mutable subscriptionClient : SubscriptionClient = null
let exceptionReceivedHandler (args:ExceptionReceivedEventArgs) =
printfn "Got an exception: %A" args.Exception
Task.CompletedTask
let processMessageAsync (message:Message) (_:CancellationToken) =
try
let _ = Encoding.UTF8.GetString(message.Body)
subscriptionClient.CompleteAsync(message.SystemProperties.LockToken) |> Async.AwaitTask |> Async.RunSynchronously
Task.CompletedTask
with
_ -> Task.CompletedTask
member x.Listen() =
async {
subscriptionClient <- new SubscriptionClient(connectionString, topic, subscription)
subscriptionClient.OperationTimeout <- TimeSpan.FromMinutes(3.0)
let! rulesFound = subscriptionClient.GetRulesAsync() |> Async.AwaitTask
let hasDefaultRule = rulesFound.Any(fun r -> r.Name = RuleDescription.DefaultRuleName)
if hasDefaultRule then
do! subscriptionClient.RemoveRuleAsync(RuleDescription.DefaultRuleName) |> Async.AwaitTask
let msgOptions = MessageHandlerOptions(fun args -> exceptionReceivedHandler(args))
msgOptions.AutoComplete <- false
msgOptions.MaxAutoRenewDuration <- TimeSpan.FromMinutes(1.0)
msgOptions.MaxConcurrentCalls <- 1
subscriptionClient.RegisterMessageHandler(processMessageAsync, msgOptions)
}
member x.CloseAsync() =
async {
do! subscriptionClient.CloseAsync() |> Async.AwaitTask
}
İşte çalıştırmayı denediğinizde nasıl abone :
open System
open Subscription.Console
let connectionString = <connection_string>
[<EntryPoint>]
let main argv =
printfn "Welcome to Subscription.Console"
let topic,subscription = "Topic.courier-accepted","Subscription.all-messages"
let subscriber = Subscriber(connectionString, topic, subscription)
async { do! subscriber.Listen()
} |> Async.RunSynchronously
Console.ReadKey() |> ignore
async { do! subscriber.CloseAsync()
} |> Async.RunSynchronously
0 // return an integer exit code
Aşağıdaki kod, abonemin alması gereken (ancak almadığı) bir mesaj yayınlar :
[<Fact>]
let ``Publish courier-accepted to servicebus``() =
async {
// Setup
let client = TopicClient(sbConnectionstring, "Topic.courier-accepted")
let! requestId = requestId()
let updated = requestId |> modifyRequestId someCourierResponse
let json = JsonConvert.SerializeObject(updated)
let message = Message(Encoding.UTF8.GetBytes(json))
message.Label <- sprintf "request-id(%s)" (requestId.ToString())
// Test
do! client.SendAsync(message) |> Async.AwaitTask
// Teardown
do! client.CloseAsync() |> Async.AwaitTask
}
NOT:
Yukarıdaki kodla ilgili ilginç olan şey, aynı konu ve abonelik adına ayarlanmış bir ServiceBusTrigger ile çalışan bir Azure İşlevim olduğunda, testi her çalıştırdığımda Azure İşlevinin tetiklenmesidir.
- İstisna mesajı almıyorum
- ExceptionReceivedHandler işlevi Abone örneğimde hiçbir zaman tetiklenmiyor
- Servicebus kaynağı için Azure kontrol panelimde herhangi bir kullanıcı hatası gözlemlemiyorum
Farklı konu adlarıyla başarılı
Konu adını "kurye tarafından talep edildi" olarak değiştirirsem, abone örneği ileti alır:
[<Fact>]
let ``Publish courier-requested to servicebus topic``() =
// Setup
let client = TopicClient(sbConnectionstring, "Topic.courier-requested")
let message = Message(Encoding.UTF8.GetBytes(JsonFor.courierRequest))
message.Label <- sprintf "courier-id(%s)" "b965f552-31a4-4644-a9c6-d86dd45314c4"
// Test
async {
do! client.SendAsync(message) |> Async.AwaitTask
do! client.CloseAsync() |> Async.AwaitTask
}
Konu adı ayarlaması olan abonelik şöyledir:
[<EntryPoint>]
let main argv =
printfn "Welcome to Subscription.Console"
let topic,subscription = "Topic.courier-requested","Subscription.all-messages"
let subscriber = Subscriber(connectionString, topic, subscription)
async { do! subscriber.Listen()
} |> Async.RunSynchronously
Console.ReadKey() |> ignore
async { do! subscriber.CloseAsync()
} |> Async.RunSynchronously
0 // return an integer exit code
Azure Portal'ımdaki iki konu şunlardır:
Portal'da Tıklama Konularının sonuçları farklıdır:
Aboneliklerini görüntülemek için "kurye kabullü" yi iki kez tıklatmam gerektiğini fark ettim. Ancak, "kurye tarafından talep edilen" i bir kez tıklayabilir ve hemen aboneliklerini görüntüleyebilirim.
I don't receive any exception messages
, belki de istisnaları yuttuğunuz için? Bir bakınwith _
, bir sonraki bloktry
tek