示例#1
0
// Creates a new KafkaTransport instance with sensible default values.
func NewTransport(brokers []string, zkHosts []string, inputBinding string, outputBinding string) *Transport {
	if len(brokers) == 0 {
		brokers = make([]string, 1)
		brokers[0] = "localhost:9092"
		log.Debugf("No Kafka brokers set. Using localhost:9092")
	}
	if len(zkHosts) == 0 {
		zkHosts = make([]string, 1)
		zkHosts[0] = "localhost:2181"
		log.Debugf("No Zookeeper hosts set. Using localhost:2181")
	}
	if inputBinding == "" {
		inputBinding = "input"
	}
	if outputBinding == "" {
		outputBinding = "output"
	}

	transport := &Transport{
		Transport: api.Transport{
			InputBinding:   transport.EscapeTopicName(transport.StripPrefix(inputBinding)),
			InputSemantic:  transport.GetBindingSemantic(inputBinding),
			OutputBinding:  transport.EscapeTopicName(transport.StripPrefix(outputBinding)),
			OutputSemantic: transport.GetBindingSemantic(outputBinding),
		},
		Brokers:                   brokers,
		ZookeeperHosts:            zkHosts,
		TopicReadinessWaitTimeSec: 120,
	}

	return transport
}
示例#2
0
// NewTransport creates a new Redis-based transport instance with sensible default values.
// Either address or sentinel address (and also set sentinelMaster) has to be set.
func NewTransport(address string, sentinelMaster string, inputBinding string, outputBinding string) *Transport {

	// set some reasonable defaults
	if address == "" || address == ":6379" {
		address = "localhost:6379"
	} else { // check if it has a port

		match, _ := regexp.MatchString("^.+:\\d+$", address)
		if !match {
			log.Debugf("Appending default redis port :6379 to %s", address)
			address = address + ":6379"
		}
	}
	if inputBinding == "" {
		inputBinding = "input"
	}
	if outputBinding == "" {
		outputBinding = "output"
	}

	transport := &Transport{
		Transport: api.Transport{
			InputBinding:   transport.Prefix(inputBinding),
			InputSemantic:  transport.GetBindingSemantic(inputBinding),
			OutputBinding:  transport.Prefix(outputBinding),
			OutputSemantic: transport.GetBindingSemantic(outputBinding),
		},
		Address:        address,
		SentinelMaster: sentinelMaster,
		Timeout:        1,   // TODO parameterize via CLI?
		MaxConnections: 100, // TODO parameterize via CLI?
	}
	return transport
}