#KafkaListener with topicPattern and consumer group name based on the topic assigned - spring-kafka

I would like to use #KafkaListener and base the consumer group on the name of the topic
attached but using a topic pattern.
Example with a single topic
#KafkaListener(
id = "test",
topic= "tenant15",
groupId = "my_group_tenant15")
I would like to generalize this with a topicPattern (tenant*) instead of static topic
Any idea how to do this ?
Thank you

It cannot be done; the group is needed when creating the consumer whereas the topic(s) matching the pattern will be assigned later.

Related

How to manage groups in SignalR core? (joining/leaving from all)

I have some questions about SignalR.
An app scenario: An user can join/leave to many groups (NxN). But
those groups can be changed with a new request. So, how to remove an
user from all joined groups and add him to new list of groups? (Such
as: in first request i join A,B,C groups and with second request i
want to be in only groupS X,Z -i'm not listening a,b,c groups anymore-).
How to check a group name if it's already exists?
How to remove a group if it has no users/members in it? (garbage collector)
Hope someone helps me here!
(Signalr core: 2.2)
SignalR don't provide you the list of users that are in groups, how many groups there are and their names. So the logic that you need to implement is create for example a Dictionary so you can add there the name of your group and the users that are associated to that group. So when a request comes to change user from group A to group B you can do:
Lookup in what groups the user is.
Remove the user from the group.
Create the new group and add it to your Dictionary.
Add the user to the new group.
I believe this is a good aproach if you have one SignalR app/host because if you will have many instances of your signalR app, you can not access to the Dictionary to see if there is a user in some group in some other instance.

How to handle commands for aggregates with IDs assigned after command?

I know the subject line doesn't make sense given the way Axon works, but here is my problem:
I need to create a new instance of aggregate, "Quote", that is tied to a backend system of record. That is, the aggregate ID must eventually match the ID assigned in the backend system.
So, my uiServer app is calling commandGateway and sending it a CreateQuoteCmd, but I don't know what to pass as the target aggregate ID, since the ID will come from a backend system called by the command handler. The uiServer cannot assign the quoteId. The command handler for CreateQuoteCmd contacts our backend system to get the new quoteId. The backend system also supplies several default values which will be placed in the aggregate.
So, how do I make that quoteId the ID for the aggregate?
What do I pass as the target aggregate ID in the command object?
Is it true that I must pass a target aggregate ID in CreateQuoteCmd instead of allowing the object to set its own ID in the command handler after communication with the backend system?
Thanks for your help.
The Command which will create an Aggregate is not inclined to have a #TargetAggregateIdentifier annotated field. This holds as the field which is the 'target aggregate identifier', cannot point to an existing aggregate, as that command will be the starting point of an aggregate.
The creation of the Aggregate Identifier can happen at several points in your system, and is really up to you.
The important part here though is that the #CommandHandler annotated constructor within an Aggregate has a return value, which is the Aggregate Identifier you have assigned to that Aggregate.
You should thus handle the result given to you from the CommandGateway/CommandBus when dispatching your CreateQuoteCmd. This should contain the QuoteId you have assigned to your (I assume) Quote Aggregate.
You need to get the aggregate ID from the external system before sending the command (at domain or application service layer)

Are fungible states automatically merged on Corda?

I want to create a custom fungible asset on corda.. It is unclear to me how states that implement FungibleAsset are handled internally. Say I receive ten 1 dollar CoinStates from a transaction, are those merged to one 10 dollar Coinstate which I then use as the one and only input state if I wanted to make a payment myself?
basically I want something like the Cash.generateSpend which unfortunately is not very well documented
My approach so far for a transferFlow:
I have a function that does a vault query and should return some parties balance.. (this is assuming that the balance amount is internally merged to one state)
then using this balance as Input state I have a check if the input is equal the amount to pay in which case I will simply create one output state of the same amount but a new owner, otherwise I create another output state with the amount of change and myself as the owner
This is the function so far...
I have a function that does a vault query and should return some parties balance..
StateAndRef<CurrencyState> getBalaceOfIdentiy(AbstractParty id) throws FlowException {
QueryCriteria queryCriteria = new QueryCriteria.FungibleAssetQueryCriteria(null,ImmutableList.of(id),null, null,
null, null, null
);
// this assumes states are merged internally
List<StateAndRef<CurrencyState>> balanceOfID = getServiceHub().getVaultService().queryBy(CurrencyState.class, queryCriteria).getStates();
return balanceOfID.get(0);
}
Corda follows UTXO model. I'm not sure which version of Corda you are on but if you'll look closely enough you'll find that it would call OnLedgerAsset.generateSpend at some point of time and that does the job for you. and can be statically used as it is annotated with #JvmStatic.

Fetching details of a group user belongs to in firebase

Below is my database structure in firebase. I only have signed-in users Id.
User
-userId
-Name
-age
-groups
groupId1:true
groupId2:true
Group
-groupId
-name
-desc
-UserId
-UserId1:true
-UserId2:true
I want to list the details of all the groups that user belongs to.
My approach is,
Find all the groups my user belongs to by checking the index from User.
Using the list of groupid we got from step1, get details of group from Groups.
Is there any other better suggestions?
With your current data structure you will indeed have to do the two-stepped approach:
Load the list of group IDs
Load the metadata (e.g. name) of each group
This is known as a client-side join and is quite common with Firebase.
Alternatively you can duplicate the most important information about each group under each user's groups. E.g.
UserGroups
User1
Group1: "This is the first group"
Group2: "This is the second group"
As you see in this sample we've replace the true marker with the actual name of the group. The advantage of this is that for a simple use-case you only have to read this list and not do a client-side join. A disadvantage is that you need to decide whether/how to keep the data sync. I wrote an answer with the option for that here: How to write denormalized data in Firebase
Note that your data model is not fully flattened, since you're mixing entity types. I recommend splitting the metadata of each user (their name and description) from the "list of groups that the user belongs to". That leaves you with four top-level lists:
Users
Groups
UserGroups
GroupUsers
This is a common pattern for many-to-many relations, which I further described here: Many to Many relationship in Firebase
Below method will retrieve the Group details which user belongs to.
self.usersPerGroupRef = [_rootRef child:#"Group"];
[_usersPerGroupRef observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
self.usersArray = [NSMutableArray new];
for (snapshot in snapshot.children) {
NSMutableDictionary *groupDict = [NSMutableDictionary new];
groupDict = snapshot.value[#"UserId"];
if ([groupDict objectForKey:#"userID"]) {
NSLog(#"Group Name: %#",snapshot.value[#"name"]);
[self.usersArray addObject:snapshot.key];
}
}
}];

get auto-generated id (objectify datastore)

i want to pass autogenerated id to 'Name/id' at datastore.can anybody help me for this? here is my code :
String Id = "" // i want autogenerated value
profile = new Profile(Id, displayName, mainEmail);
Id must be autogenerated here. so how to pass it?
ObjectifyFactory has a method #allocateId(). You ca find an example usage in this question.
Essentially you do
new ObjectifyFactory().allocateId(Profile.class).getId()
In case you do not need the id right away I would not use this approach. Just annotate the id with #Id, set it to null and save the entity. When you do a ofy().save().entity(...).now() it will return a Key that contains the new id.
Allocating ids via allocated id still performs a datastore request. It will allocate a block of ids of which you will use just one in this case. Use it if you must, don't, if you don't have to.

Resources