Reputation: 17451
Completely new to Axon here.
I have a class defined in Kotlin:
data class ProjectedQuote(
@Id var submissionId: String,
var periodId: String,
var accountNumber: String
)
It gets instantiated and updated by event handlers, then it is returned in response to queries.
I'm needing to create a query that finds a ProjectedQuote instance by accountNumber
, not id
. I'm not sure how to do that.
To date, I've only done queries like:
SELECT q FROM ProjectedQuote q WHERE q.id LIKE CONCAT(:idStartsWith, '%') ORDER BY q.id
My narrowly-focused question is:
How do I write a query that finds ProjectedQuote using accountNumber
instead of id
?
My broader question is:
How can I see what fields are available to query by in the Axon databases?
Upvotes: 0
Views: 168
Reputation: 7275
What Sergey points out here too is very valid. How you model your Query Model in such an application is entirely up to you. So pick JPA, JDBC, MongoDB, ElasticSearch, Neo4j..whichever format of containing the Query Model suites you best!
This freedom of storage mechanisms thus also points out that your Query Model isn't stored in an 'Axon Database'; it's stored in the database you have chosen.
In regards to how to model your queries, you could have a look at how QueryMessages
and QueryHandlers
can be used in Axon, over here. This is just another dedicated type of message from Axon's perspective, just like Command- and EventMessages.
Using Query Messages, you can specify the type of query you'd want to perform as a separate object, which is the query.
This query will in turn be handled by an @QueryHandler
annotated function.
The @QueryHandler
annotated function will in turn perform the actual operation to retrieving the model from the database you have chosen to use to store the model in.
Hope this gives you some insights!
Upvotes: 1
Reputation: 2405
Query messages typically read data from the view models created by the event listeners. Event listeners typically execute logic based on decisions that have been made by the command model. Usually, this involves updating view models or forwarding updates to other components.
So the mechanism for creating and receiving views is entirely up to you. (jpa, spring data, mybatis, jdbc etc.) A good example the axon project is https://github.com/idugalic/digital-restaurant
Upvotes: 1