兔子在春季检索一个物体

发布于 2025-02-12 03:47:48 字数 2089 浏览 1 评论 0原文

我有一个正在使用@rabbitlistener注释的消费者类,我需要检索我在有效载荷中获得的对象:

@Component
public class RabbitMQService {

    private final Logger logger = LoggerFactory.getLogger(RabbitMQService.class);

    @RabbitListener(queues = "${peopleevents.queue}")
    public void receivedMessage(@Payload Message message) throws JsonProcessingException {

        String json = "";

        json = new String(message.getBody(), StandardCharsets.UTF_8);

        logger.info("Received message: {}", json);

        ObjectMapper objectMapper = new ObjectMapper();
        PeopleCoresConsumerDTO consumerDTO = objectMapper.readValue(json, PeopleCoresConsumerDTO.class);
        logger.info("Received message is.. " + message.toString());
    }

我正在使用objectMapper来获取它,但我认为我在这里缺少一些东西来完全检索对象回来,但我不知道吗?有帮助!??

DTO如下:

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PeopleCoresConsumerDTO {

    @JsonProperty(value = "processType")
    @NotNull(message = "ProcessType is mandatory")
    private String processType;

    @JsonProperty(value = "operation")
    @NotNull(message = "Operation is mandatory")
    private String operation;

    @JsonProperty(value = "Entity")
    @NotNull(message = "Entity is mandatory")
    private String entity;

    @JsonProperty(value = "EntityType")
    @NotNull(message = "EntityType is mandatory")
    private String entityType;

    @JsonProperty(value = "IdCuco")
    @NotNull(message = "IdCuco is mandatory")
    private Long idCuco;

    @JsonProperty(value = "PersonF")
    private PersonF personF;

    @JsonProperty(value = "Address")
    private Address address;

    @JsonProperty(value = "Document")
    private Document document;

    @JsonProperty(value = "Ban")
    private Ban ban;

    @JsonProperty(value = "Dates")
    private PeopleDate date;

    @Getter
    @Setter
    class Customer {
        private String systemId;
        private String customerId;
    }

    private List<Customer> customers;

}

I have this consumer class who is using the @RabbitListener annotation and I need to retrieve the object which I'm getting in the Payload:

@Component
public class RabbitMQService {

    private final Logger logger = LoggerFactory.getLogger(RabbitMQService.class);

    @RabbitListener(queues = "${peopleevents.queue}")
    public void receivedMessage(@Payload Message message) throws JsonProcessingException {

        String json = "";

        json = new String(message.getBody(), StandardCharsets.UTF_8);

        logger.info("Received message: {}", json);

        ObjectMapper objectMapper = new ObjectMapper();
        PeopleCoresConsumerDTO consumerDTO = objectMapper.readValue(json, PeopleCoresConsumerDTO.class);
        logger.info("Received message is.. " + message.toString());
    }

I'm using objectmapper to get it but I think that I'm missing something here to completely retrieve the object back, but I don't know what? Any help!!??

The DTO is as follows:

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown=true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PeopleCoresConsumerDTO {

    @JsonProperty(value = "processType")
    @NotNull(message = "ProcessType is mandatory")
    private String processType;

    @JsonProperty(value = "operation")
    @NotNull(message = "Operation is mandatory")
    private String operation;

    @JsonProperty(value = "Entity")
    @NotNull(message = "Entity is mandatory")
    private String entity;

    @JsonProperty(value = "EntityType")
    @NotNull(message = "EntityType is mandatory")
    private String entityType;

    @JsonProperty(value = "IdCuco")
    @NotNull(message = "IdCuco is mandatory")
    private Long idCuco;

    @JsonProperty(value = "PersonF")
    private PersonF personF;

    @JsonProperty(value = "Address")
    private Address address;

    @JsonProperty(value = "Document")
    private Document document;

    @JsonProperty(value = "Ban")
    private Ban ban;

    @JsonProperty(value = "Dates")
    private PeopleDate date;

    @Getter
    @Setter
    class Customer {
        private String systemId;
        private String customerId;
    }

    private List<Customer> customers;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2025-02-19 03:47:48

只需将jackson2jsonmessageconverter @bean添加到上下文中,然后

@RabbitListener(queues = "${peopleevents.queue}")
public void receivedMessage(@Payload PeopleCoresConsumerDTO consumerDTO) {
   ...
}

Just add a Jackson2JsonMessageConverter @Bean to the context, and then

@RabbitListener(queues = "${peopleevents.queue}")
public void receivedMessage(@Payload PeopleCoresConsumerDTO consumerDTO) {
   ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文