예제 #1
0
 def UpdateCustomerAddress(self,Command:UpdateCustomerAddressCommand):
     Events, Data = CustomerRepository().Find('Customer',Command.CustomerId) #loads all entity's events
     UpdatedCustomer = Customer()
     UpdatedCustomer.apply(Data, Events) #restores the entity to its current state
     try:
         Events = UpdatedCustomer.processForCustomerUpdateAddress(Command)
     except AddressException:
         return f'This was your address already'
     UpdatedCustomer.applyForCustomerUpdateAddress(Events[0])
     CustomerRepository().Update((UpdatedCustomer,), Events) #Insert the event to the database
     return f'You changed your address successfully'
예제 #2
0
 def Do_BankTransaction(self, Command: DoBankTransactionCommand):
     UpdatedCustomer = Customer()
     EventsToRevise, SnapshotData = CustomerRepository().Find(
         Command.CustomerId, 'Customer')
     UpdatedCustomer.Revise(SnapshotData, EventsToRevise)
     Events = UpdatedCustomer.procces_Do_BankTransaction_Command(Command)
     Sg = Saga()
     Sg.Create(Command.OrderId, 'CreateOrderSaga',
               Events[1].EventJsonData())
     UpdatedCustomer.applyAccountAuthorizedEvent(Events[0])
     CustomerRepository().Update((UpdatedCustomer, Sg), Events,
                                 Command.MessageId)
예제 #3
0
 def VerifyCustomer(self,Command:VerifyCustomerCommand):
     NewOrder = Order()
     Saga = SagaParticipant()
     Events = NewOrder.proccessForVerifyCustomerCommand(Command)
     Saga.Create(Command.OrderId,Events[1].EventJsonData(),Command.SagaType)        
     NewOrder.applyForVerifyCustomerEvent(Events[0])
     CustomerRepository().Create((NewOrder,Saga),Events,MessageId=Command.MessageId) #Insert the event to the database
예제 #4
0
 def delivery_report(self, err, msg, Details):
     msg = json.loads(msg)
     print(
         f'Message:Send, Service: Πελάτες, EventType:{msg["Message"]["Head"]["EventType"]}'
     )
     CustomerRepository().UpdateEventThatItHasBeenPublished(
         Details[0], Details[1],
         Details[2])  #Update the event that was published successfully
예제 #5
0
    def SendMessagesToMessageBroker(self):

        UnpublishedEvents = CustomerRepository().GetUnpublishedEvents() #loads unpuplished events
        MC = MessageCreator()
        for Event in UnpublishedEvents:
            if Event.eventtype not in ['CustomerVerifiedEvent','CustomerNotVerifiedEvent']:  #If the type of the eventis not one of these in the list
                Details = [Event.entityid,Event.entitytype,Event.eventtime,Event.eventtype]        
                Message, Topics  = MC.ProduceMessage(Event.entityid, Event.eventdata, Event.eventtype,Details)  #Creates the message that will be send to Kafka
                for Topic in Topics:
                    self.ProduceToBroker.Publish(Message, Topic, Details) #Send the event to Kafka
예제 #6
0
 def proccessForVerifyCustomerCommand(self, Command):
     if CustomerRepository().VerifyCustomer(Command.CustomerId):
         return [
             CustomerVerifiedEvent(Command.OrderId, Command.CustomerId,
                                   True),
             SagaReplyEvent(Command='CustomerVerified', Verified=True)
         ]
     else:
         return [
             CustomerNotVerifiedEvent(Command.OrderId, Command.CustomerId,
                                      False),
             SagaReplyEvent(Command='CustomerNotVerified', Verified=False)
         ]
예제 #7
0
def Consumes(c):
    
    while True:
        msg = c.poll(1.0) #Consumes Messages from Kafka

        if msg is None:
            continue
        if msg.error():
            print("Consumer error: {}".format(msg.error()))
        
        Msg = json.loads(msg.value().decode('utf-8'))
        if CustomerRepository().CheckDuplicatedMessages(Msg['Message']['Head']['MessageId']): #If Message is not duplicated
            print(f'Message:Received, Service:Πιστωτικές συναλλαγές, EventType:{Msg["Message"]["Head"]["EventType"]}')
            CommandHandler(msg.value().decode('utf-8')).CommandHandler() #Activate the CommandHandler
        c.commit(msg)  #Commits the offset of the message that it consumes

    c.close()
예제 #8
0
 def CreateAccount(self, Command: CreateAccountCommand):
     NewCustomer = Customer()
     Events = NewCustomer.procces_CreateAccount_Command(Command)
     NewCustomer.applyAccountCreatedEvent(Events[0])
     CustomerRepository().Create((NewCustomer, ), Events, Command.MessageId)
예제 #9
0
 def ReturnCustomerAddress(self,Command):
     Events = CustomerRepository().CustomerAddresTemporaryQuery(Command.CustomerId,Command.Date) #loads entity's events that occur until Command.Date 
     customer = Customer()
     customer.apply(Events[0],Events[1:]) #restores the entity to the state that it was at the time Command.Date
     return customer.Address
예제 #10
0
 def SaveCustomer(self,Command:SaveCustomerCommand)-> dict:
     NewCustomer = Customer()
     Events = NewCustomer.processForCustomerCreation(Command)
     NewCustomer.applyForCustomerCreation(Events[0])
     CustomerRepository().Create((NewCustomer,),Events) #Insert the event to the database
     return {'Id':NewCustomer.Id}