我有一个使用者类,它使用@RabbitListener注解,我需要检索在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());
}
我正在使用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;
}
1条答案
按热度按时间uxh89sit1#
只需向上下文中添加一个
Jackson2JsonMessageConverter
@Bean
,然后