package com.springboot.cloud.auth.authentication.events;

import com.springboot.cloud.auth.authentication.entity.Popedom;
import com.springboot.cloud.auth.authentication.service.PopedomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 消息接收者，收到消息后进行处理，内部反射调用，默认回调方法handleMessage,方法参数由消息
 * 发送方和接收方约定，方法参数尽可能作为一个对象，多个参数向上封装成一个对象
 *
 * @see MessageListenerAdapter
 * @see org.springframework.amqp.core.MessageListener
 */
@Component
@Slf4j
public class BusReceiver {

    @Autowired
    private PopedomService popedomService;

    public void handleMessage(List<Popedom> popedoms) {
        log.info("Received Message:<{}>", popedoms);
        popedomService.savePopedom(popedoms);
    }
}
