-
-
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.
* Updated config file for amqp * Added publisher service * Added listeners and publisher code * Updated AMQP config and added sample config files to test * Updated amqp config * Segregated declarables for exchanges and queues * Updated test snapshots * fix double dependency * fix snapshots --------- Co-authored-by: Semen <[email protected]>
- Loading branch information
1 parent
f3219d3
commit 6c611bc
Showing
12 changed files
with
265 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% macro amqpPublisher(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 %} | ||
|
||
|
||
@Service | ||
public class PublisherService { | ||
@Autowired | ||
private RabbitTemplate template; | ||
|
||
{% for channelName, channel in asyncapi.channels() %} | ||
{% if channel.hasSubscribe() %} | ||
@Value("${amqp.{{- channelName -}}.exchange}") | ||
private String {{channelName}}Exchange; | ||
@Value("${amqp.{{- channelName -}}.routingKey}") | ||
private String {{channelName}}RoutingKey; | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% for channelName, channel in asyncapi.channels() %} | ||
{% if channel.hasSubscribe() %} | ||
{%- set schemaName = channel.subscribe().message().payload().uid() | camelCase | upperFirst %} | ||
public void {{channel.subscribe().id() | camelCase}}(){ | ||
{{schemaName}} {{channelName}}Payload = new {{schemaName}}(); | ||
template.convertAndSend({{channelName}}Exchange, {{channelName}}RoutingKey, {{channelName}}Payload); | ||
} | ||
|
||
{% endif %} | ||
{% endfor %} | ||
|
||
} | ||
|
||
{% 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
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
3 changes: 3 additions & 0 deletions
3
template/src/main/java/com/asyncapi/service/PublisherService.java
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package {{ params['userJavaPackage'] }}.service; | ||
{%- from "partials/CommonPublisher.java" import commonPublisher -%} | ||
{%- from "partials/KafkaPublisher.java" import kafkaPublisher -%} | ||
{%- from "partials/AmqpPublisher.java" import amqpPublisher -%} | ||
{%- if asyncapi | isProtocol('kafka') -%} | ||
{{- kafkaPublisher(asyncapi, params) -}} | ||
{%- elif asyncapi | isProtocol('amqp') -%} | ||
{{- amqpPublisher(asyncapi, params) -}} | ||
{%- else -%} | ||
{{- commonPublisher(asyncapi) -}} | ||
{%- endif -%} |
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
Oops, something went wrong.