Kafka integration (#831)

Kafka integration with Fission enables invoking a function when a message arrives in a Kafka topic
This commit is contained in:
Vishal
2018-10-01 18:03:31 +05:30
committed by GitHub
parent 9f83d70b63
commit 96cbee185d
16 changed files with 473 additions and 39 deletions
+3 -2
View File
@@ -64,8 +64,9 @@ const (
)
const (
MessageQueueTypeNats = "nats-streaming"
MessageQueueTypeASQ = "azure-storage-queue"
MessageQueueTypeNats = "nats-streaming"
MessageQueueTypeASQ = "azure-storage-queue"
MessageQueueTypeKafka = "kafka"
)
const (
+21 -1
View File
@@ -36,6 +36,7 @@ const (
var (
validAzureQueueName = regexp.MustCompile("^[a-z0-9][a-z0-9\\-]*[a-z0-9]$")
validKafkaTopicName = regexp.MustCompile("^[a-z0-9][a-z0-9\\-._]*[a-z0-9]$")
)
type (
@@ -164,10 +165,29 @@ func IsTopicValid(mqType MessageQueueType, topic string) bool {
return nsUtil.IsChannelNameValid(topic, false)
case MessageQueueTypeASQ:
return len(topic) >= 3 && len(topic) <= 63 && validAzureQueueName.MatchString(topic)
case MessageQueueTypeKafka:
return IsValidKafkaTopic(topic)
}
return false
}
// The validation is based on Kafka's internal implementation: https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/internals/Topic.java
func IsValidKafkaTopic(topic string) bool {
if len(topic) == 0 {
return false
}
if topic == "." || topic == ".." {
return false
}
if len(topic) > 249 {
return false
}
if !validKafkaTopicName.MatchString(topic) {
return false
}
return true
}
func IsValidCronSpec(spec string) error {
_, err := cron.Parse(spec)
return err
@@ -433,7 +453,7 @@ func (spec MessageQueueTriggerSpec) Validate() error {
result = multierror.Append(result, spec.FunctionReference.Validate())
switch spec.MessageQueueType {
case MessageQueueTypeNats, MessageQueueTypeASQ: // no op
case MessageQueueTypeNats, MessageQueueTypeASQ, MessageQueueTypeKafka: // no op
default:
result = multierror.Append(result, MakeValidationErr(ErrorUnsupportedType, "MessageQueueTriggerSpec.MessageQueueType", spec.MessageQueueType, "not a supported message queue type"))
}