-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for channel parameters (#352)
* add pattern support for kafka * add pattern support for mqtt message handling * use mqtt specific wildcard * mqtt publish implementation * adopt interface for other protocols * update tests * general amqp routing key support * fix current amqp methods * provide arbitrary methods for amqp * provide arbitrary methods for mqtt * update tests * provide arbitrary methods for kafka in message handler * provide arbitrary methods for kafka in publisher * update tests * update readme, resolve missing features, add attention bar
- Loading branch information
Showing
29 changed files
with
1,538 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{% macro amqpPublisherImpl(asyncapi, params) %} | ||
|
||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
{% for channelName, channel in asyncapi.channels() %} | ||
{%- if channel.hasSubscribe() %} | ||
{%- for message in channel.subscribe().messages() %} | ||
import {{params['userJavaPackage']}}.model.{{message.payload().uid() | camelCase | upperFirst}}; | ||
{%- endfor -%} | ||
{% endif -%} | ||
{% endfor %} | ||
|
||
import javax.annotation.processing.Generated; | ||
|
||
@Generated(value="com.asyncapi.generator.template.spring", date="{{''|currentTime }}") | ||
@Service | ||
public class PublisherServiceImpl implements PublisherService { | ||
@Autowired | ||
private RabbitTemplate template; | ||
|
||
{% for channelName, channel in asyncapi.channels() %} | ||
{%- if channel.hasSubscribe() %} | ||
{%- set varName = channelName | toAmqpNeutral(channel.hasParameters(), channel.parameters()) %} | ||
@Value("${amqp.{{- varName -}}.exchange}") | ||
private String {{varName}}Exchange; | ||
@Value("${amqp.{{- varName -}}.routingKey}") | ||
private String {{varName}}RoutingKey; | ||
{%- endif %} | ||
{% endfor %} | ||
|
||
{%- set anyChannelHasParameter = false %} | ||
{% for channelName, channel in asyncapi.channels() %} | ||
{%- set anyChannelHasParameter = anyChannelHasParameter or channel.hasParameters() %} | ||
{%- if channel.hasSubscribe() %} | ||
{%- if channel.subscribe().hasMultipleMessages() %} | ||
{%- set varName = "object" %} | ||
{%- else %} | ||
{%- set varName = channel.subscribe().message().payload().uid() | camelCase %} | ||
{%- endif %} | ||
{%- set channelVariable = channelName | toAmqpNeutral(channel.hasParameters(), channel.parameters()) %} | ||
{% if channel.description() or channel.subscribe().description() %}/**{% for line in channel.description() | splitByLines %} | ||
* {{line | safe}}{% endfor %}{% for line in channel.subscribe().description() | splitByLines %} | ||
* {{line | safe}}{% endfor %} | ||
*/{% endif %} | ||
public void {{channel.subscribe().id() | camelCase}}({{varName | upperFirst}} payload){ | ||
template.convertAndSend({{channelVariable}}Exchange, {{channelVariable}}RoutingKey, payload); | ||
} | ||
|
||
{%- if channel.hasParameters() %} | ||
public void {{channel.subscribe().id() | camelCase}}({%- for parameterName, parameter in channel.parameters() %}String {{parameterName}}, {% endfor %}{{varName | upperFirst}} payload) { | ||
String compiledRoutingKey = compileRoutingKey({{channelVariable}}RoutingKey, {% for parameterName, parameter in channel.parameters() %}{{parameterName}}{% if not loop.last %}, {% endif %}{%- endfor %}); | ||
template.convertAndSend({{channelVariable}}Exchange, compiledRoutingKey, payload); | ||
} | ||
{% endif %} | ||
|
||
{% endif %} | ||
{% endfor %} | ||
|
||
{%- if anyChannelHasParameter %} | ||
private String compileRoutingKey(String routingKeyTemplate, String... parameters) { | ||
StringBuilder result = new StringBuilder(); | ||
int routeKeyPossition = 0; | ||
int parametersIndex = 0; | ||
while (routeKeyPossition < routingKeyTemplate.length()) { | ||
while (routingKeyTemplate.charAt(routeKeyPossition) != '*') { | ||
routeKeyPossition++; | ||
result.append(routingKeyTemplate.charAt(routeKeyPossition)); | ||
} | ||
routeKeyPossition++; | ||
String parameter = parameters[parametersIndex++]; | ||
result.append(parameter != null ? parameter : "*"); | ||
} | ||
return result.toString(); | ||
} | ||
{%- endif %} | ||
|
||
} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.