Skip to content

keksmd/amqp-entity-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

245 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This starter is all you need to start declarative DDD with distributed transactions(Saga is implemented) out of the box ( between services using this framework or adapters) Now we support only RabbitMQ, but we have a plan to promote Kafka support

Configuration enables automatically while you have org.springframework.amqp.rabbit.connection.ConnectionFactory bean

org.springframework.data.redis.connection.RedisConnectionFactory also enables caching

Design PET domain

@Data
@MessagingEntity(domain = PetMessagePayload.PET_DOMAIN,queues = "pet-queue")
public class PetMessagePayload {
    public static final String PET_DOMAIN = "pet";
    String id;
    String name;
    String description;
    String type;
    String status;
}

Use JPA-like repository to send messages, you need only to extend MessagingEntityRepository interface and add @EnableMessagingRepositories(basePackages = "your.package.with.repositories") to your configuration class

public interface PetMessageRepository  extends MessagingEntittyRepository<PetMessagePayload> {
}

Use handler by Domain and ActionType for handling Event and cancel it (in Saga pipeline)

@DomainHandlers(domain = "example")
public class PetHandler {
    @Autowired
    private  PetLocalService petLocalService;

    @ActionHandler(action = "created", cancelMethod = "cancelCreate")
    public void  handleCreate(PetDto petDto) {
        petLocalService.create(petDto);
    }

    @ActionHandler(PetDto petDto)
    public void handleDelete(PetDto petToRemove) {
         petLocalService.delete(petDto);
    }

    public void cancelCreate(NormalMessage message, PetDto petToRemove) {
       log.info("deleting pet due to {}",message.getO) 
       petLocalService.deleteIfExists(petDto.getId());
    }

    @ActionHandler(action = "requested")
    public Object handleQuery(NormalMessage message) {
        return petLocalService.getById(petDto);
    }
}

More details and examples you can find in the Demo-Project

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages