Пример #1
0
 public producer(LibraryServiceConfiguration config) {
   this.configuration = config;
   apolloUser = configuration.getApolloUser();
   apolloPassword = configuration.getApolloPassword();
   apolloHost = configuration.getApolloHost();
   apolloPort = configuration.getApolloPort();
   stompQueue = configuration.getStompQueueName();
 }
 public Listener(LibraryServiceConfiguration config, BookRepositoryInterface bookRepository) {
   this.configuration = config;
   this.bookRepository = bookRepository;
   apolloUser = configuration.getApolloUser();
   apolloPassword = configuration.getApolloPassword();
   apolloHost = configuration.getApolloHost();
   apolloPort = configuration.getApolloPort();
   stompTopic = configuration.getStompTopicName();
 }
  @Override
  public void run(LibraryServiceConfiguration configuration, Environment environment)
      throws Exception {
    // This is how you pull the configurations from library_x_config.yml
    String queueName = configuration.getStompQueueName();
    String topicName = configuration.getStompTopicName();
    String instanceName = configuration.getInstanceName();
    String user = configuration.getApolloUser();
    String password = configuration.getApolloPassword();
    String host = configuration.getApolloHost();
    int port = Integer.parseInt(configuration.getApolloPort());
    log.debug("Queue name is {}. Topic name is {}", queueName, topicName);
    // TODO: Apollo STOMP Broker URL and login

    StompJmsConnectionFactory factory = new StompJmsConnectionFactory();
    factory.setBrokerURI("tcp://54.215.210.214:61613");

    Connection connection = factory.createConnection(user, password);
    connection.start();

    /** Root API */
    environment.addResource(RootResource.class);
    /** Books APIs */
    BookRepositoryInterface bookRepository = new BookRepository();
    environment.addResource(
        new BookResource(
            bookRepository,
            queueName,
            topicName,
            instanceName,
            user,
            password,
            host,
            port,
            connection));

    /** UI Resources */
    environment.addResource(new HomeResource(bookRepository));
  }