@JsonCreator public TopicWithSchema(@JsonProperty("schema") String schema, @JsonProperty("name") String qualifiedName, @JsonProperty("description") String description, @JsonProperty("owner") OwnerId owner, @JsonProperty("retentionTime") RetentionTime retentionTime, @JsonProperty("jsonToAvroDryRun") boolean jsonToAvroDryRunEnabled, @JsonProperty("ack") Ack ack, @JsonProperty("trackingEnabled") boolean trackingEnabled, @JsonProperty("migratedFromJsonType") boolean migratedFromJsonType, @JsonProperty("schemaVersionAwareSerializationEnabled") boolean schemaVersionAwareSerializationEnabled, @JsonProperty("contentType") ContentType contentType, @JsonProperty("maxMessageSize") Integer maxMessageSize, @JsonProperty("auth") PublishingAuth publishingAuth, @JsonProperty("subscribingRestricted") boolean subscribingRestricted, @JsonProperty("offlineStorage") TopicDataOfflineStorage offlineStorage) { super(qualifiedName, description, owner, retentionTime, jsonToAvroDryRunEnabled, ack, trackingEnabled, migratedFromJsonType, schemaVersionAwareSerializationEnabled, contentType, maxMessageSize, publishingAuth, subscribingRestricted, offlineStorage); this.topic = convertToTopic(); this.schema = schema; }
@Override public void check(Message message, Topic topic) { if (ContentType.AVRO != topic.getContentType() || (ContentType.JSON == topic.getContentType() && !topic.isJsonToAvroDryRunEnabled())) { return; } BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(message.getData(), null); try { new GenericDatumReader<>(message.getSchema()).read(null, binaryDecoder); } catch (Exception e) { String reason = e.getMessage() == null ? ExceptionUtils.getRootCauseMessage(e) : e.getMessage(); throw new InvalidMessageException("Could not deserialize avro message with provided schema", ImmutableList.of(reason)); } } }
private Message create(HeaderMap headerMap, Topic topic, String messageId, byte[] messageContent) { long timestamp = clock.millis(); switch (topic.getContentType()) { case JSON: { if (topic.isJsonToAvroDryRunEnabled()) { try { createAvroMessage(headerMap, topic, messageId, messageContent, timestamp); } catch (AvroConversionException exception) { logger.warn("Unsuccessful message conversion from JSON to AVRO on topic {} in dry run mode", topic.getQualifiedName(), exception); } catch (WrappingException exception) { logger.warn("Unsuccessful wrapping of AVRO message on topic {} in dry run mode", topic.getQualifiedName(), exception); } } return createJsonMessage(headerMap, messageId, messageContent, timestamp); } case AVRO: return createAvroMessage(headerMap, topic, messageId, messageContent, timestamp); default: throw new UnsupportedContentTypeException(topic); } }
public void createTopicWithSchema(TopicWithSchema topicWithSchema, String createdBy, CreatorRights isAllowedToManage) { Topic topic = topicWithSchema.getTopic(); topicValidator.ensureCreatedTopicIsValid(topic, isAllowedToManage); ensureTopicDoesNotExist(topic); boolean validateAndRegisterSchema = AVRO.equals(topic.getContentType()) || (topic.isJsonToAvroDryRunEnabled() && topicWithSchema.getSchema() != null); validateSchema(validateAndRegisterSchema, topicWithSchema, topic); registerAvroSchema(validateAndRegisterSchema, topicWithSchema, createdBy); createTopic(topic, createdBy); }