forked from asyncapi/java-spring-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix_empty_object_generation
- Loading branch information
Showing
31 changed files
with
1,542 additions
and
260 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.