-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
CommandLinePublisher.java
31 lines (25 loc) · 1.23 KB
/
CommandLinePublisher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package {{ params['userJavaPackage'] }}.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.processing.Generated;
import java.util.Random;
@Generated(value="com.asyncapi.generator.template.spring", date="{{''|currentTime }}")
@Component
public class CommandLinePublisher implements CommandLineRunner {
@Autowired
PublisherService publisherService;
@Override
public void run(String... args) {
System.out.println("******* Sending message: *******");
{%- for channelName, channel in asyncapi.channels() %}
{%- if channel.hasSubscribe() %}
{%- for message in channel.subscribe().messages() %}
publisherService.{{channel.subscribe().id() | camelCase}}({% if asyncapi | isProtocol('kafka') %}(new Random()).nextInt(), new {{ params['userJavaPackage'] }}.model.{{message.payload().uid() | camelCase | upperFirst}}()
{% elif asyncapi | isProtocol('amqp') %}{% else %}"Hello World from {{channelName}}"{% endif %});
{% endfor -%}
{% endif -%}
{%- endfor %}
System.out.println("Message sent");
}
}