Beispiel #1
0
func topicMatchFunc(msg amq.Message, binding *amq.Binding) bool {
	patternCache.RLock()
	defer patternCache.RUnlock()

	if matcher, found := patternCache.cache[binding.Key]; found {
		return matcher.MatchString(msg.RoutingKey())
	} else {
		pattern := strings.Replace(binding.Key, ".", `\.`, -1)
		pattern = strings.Replace(pattern, "*", `[0-9A-z]+`, -1)
		pattern = strings.Replace(pattern, `\.#\.`, `(\.|\.[0-9A-z\.]*\.)`, -1)
		pattern = strings.Replace(pattern, `\.#`, `(\.[0-9A-z\.]*)?`, -1)
		pattern = strings.Replace(pattern, `#\.`, `([0-9A-z\.]*\.)?`, -1)
		pattern = strings.Replace(pattern, "#", `[0-9A-z\.]*`, -1)

		matcher := regexp.MustCompile(fmt.Sprintf("^%s$", pattern))

		go func() {
			patternCache.Lock()
			defer patternCache.Unlock()

			patternCache.cache[binding.Key] = matcher
		}()

		return matcher.MatchString(msg.RoutingKey())
	}
}
Beispiel #2
0
func directMatchFunc(msg amq.Message, binding *amq.Binding) bool {
	return msg.RoutingKey() == binding.Key
}