兔子在春季检索一个物体
我有一个正在使用@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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将
jackson2jsonmessageconverter
@bean
添加到上下文中,然后Just add a
Jackson2JsonMessageConverter
@Bean
to the context, and then