本文整理匯總了Java中org.apache.kafka.connect.data.Schema.OPTIONAL_BYTES_SCHEMA屬性的典型用法代碼示例。如果您正苦於以下問題:Java Schema.OPTIONAL_BYTES_SCHEMA屬性的具體用法?Java Schema.OPTIONAL_BYTES_SCHEMA怎麽用?Java Schema.OPTIONAL_BYTES_SCHEMA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.kafka.connect.data.Schema
的用法示例。
在下文中一共展示了Schema.OPTIONAL_BYTES_SCHEMA屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toSourceRecord
/**
* Convert a message into a Kafka Connect SourceRecord.
*
* @param context the JMS context to use for building messages
* @param topic the Kafka topic
* @param messageBodyJms whether to interpret MQ messages as JMS messages
* @param message the message
*
* @return the Kafka Connect SourceRecord
*
* @throws JMSException Message could not be converted
*/
@Override public SourceRecord toSourceRecord(JMSContext context, String topic, boolean messageBodyJms, Message message) throws JMSException {
Schema valueSchema = null;
Object value = null;
// Interpreting the body as a JMS message type, we can accept BytesMessage and TextMessage only.
// We do not know the schema so do not specify one.
if (messageBodyJms) {
if (message instanceof BytesMessage) {
log.trace("Bytes message with no schema");
value = message.getBody(byte[].class);
}
else if (message instanceof TextMessage) {
log.trace("Text message with no schema");
value = message.getBody(String.class);
}
else {
log.error("Unsupported JMS message type {}", message.getClass());
throw new ConnectException("Unsupported JMS message type");
}
}
else {
// Not interpreting the body as a JMS message type, all messages come through as BytesMessage.
// In this case, we specify the value schema as OPTIONAL_BYTES.
log.trace("Bytes message with OPTIONAL_BYTES schema");
valueSchema = Schema.OPTIONAL_BYTES_SCHEMA;
value = message.getBody(byte[].class);
}
return new SourceRecord(null, null, topic, valueSchema, value);
}
示例2: toConnectData
@Override
public SchemaAndValue toConnectData(String topic, byte[] value) {
return new SchemaAndValue(Schema.OPTIONAL_BYTES_SCHEMA, value);
}