Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting NServiceBus Subscriptions from RavenDB
    text
    copied!<p>Has anyone tried (and succeeded) to get subscriptions out of RavenDB with the Raven DB .Net client? </p> <p>Having some Json serialisation issues that when the following runs, it throws with a </p> <p><em>"Error converting value "Subscriber.Messages.Events.MyEvent, Version=1.0.0.0" to type 'NServiceBus.Unicast.Subscriptions.MessageType'.</em> message</p> <p>The code is simple : </p> <pre><code> var documentStore = new DocumentStore { Url = "http://localhost:8080/", DefaultDatabase = "publisher", }; documentStore.Initialize(); using (var session = documentStore.OpenSession()) { return session.Query&lt;NServiceBus.Unicast.Subscriptions.Raven.Subscription&gt;("Raven/DocumentsByEntityName").ToArray(); } </code></pre> <p>It's definitely a serialisation issue as the retrieval works. As it does using the alternative below: </p> <pre><code>session.Advanced.LuceneQuery&lt;Subscription&gt;("Raven/DocumentsByEntityName").QueryResult.Results[0] </code></pre> <p>In the RaveDB studio I can see the following document in the publisher database. </p> <pre><code>{ "MessageType": "Subscriber.Messages.Events.MyEvent, Version=1.0.0.0", "Clients": [ { "Queue": "samplesubscriber", "Machine": "myDesktopHere" } ] } </code></pre> <p>Error converting value "Subscriber.Messages.Events.MyEvent, Version=1.0.0.0" to type 'NServiceBus.Unicast.Subscriptions.MessageType'.</p> <p>Anyone have a clue why the serialization fails? </p> <p>I'm using NServiveBus.Host 4.2, Raven-DB client 1.0.616, and Newtonsoft.json 4.0.5. </p> <p>Incidentally I've pulled up the types using dotpeek and created local versions. I created my own subcription, MessageType, MessageTypeConvertor from the NSB dll's. I then managed to deserialise the strings without issue. Any thoughts?</p> <p><strong>EDIT</strong></p> <p>As per suggestions the advance Lucene query does a great job of retrieving the results. But then deserialization fails. For example, search results are returned in the first line, but fail to deserlize in the return statement. I've pulled up a local version of the Subscription type from the NSB dll's, and implemented the type converter, again pulled up from the NSB libraries, and using those in place of NServiceBus.Unicast.Subscriptions.Raven.Subscription works fine. Inevitably, that's not a stable choice. </p> <pre><code>var searchResults = session.Advanced.LuceneQuery&lt;NServiceBus.Unicast.Subscriptions.Raven.Subscription&gt;("Raven/DocumentsByEntityName").WhereEquals("Tag", "Subscription").QueryResult.Results; return searchResults.Select(subscriptionJsonObject =&gt; JsonConvert.DeserializeObject&lt;NServiceBus.Unicast.Subscriptions.Raven.Subscription&gt;(subscriptionJsonObject.ToString())).ToList(); </code></pre> <p>Any further thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload