package com.huangzj.server.event;

import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 随便听听 {@link AppDomainEvent}，记一下次数和最后一条，方便 HTTP 查状态。
 */
@Component
public class DemoEventListener {

    private final AtomicInteger receiveCount = new AtomicInteger();
    private volatile String lastTopic;
    private volatile String lastBody;

    @EventListener
    public void onDomain(AppDomainEvent event) {
        receiveCount.incrementAndGet();
        lastTopic = event.getTopic();
        lastBody = event.getBody();
    }

    public int getReceiveCount() {
        return receiveCount.get();
    }

    public String getLastTopic() {
        return lastTopic;
    }

    public String getLastBody() {
        return lastBody;
    }
}
