2016-12-30 8 views
0

AWS SQS를 처음 사용하고 있습니다. 나는 방화벽을 통해 로컬 네트워크에서 SQS로 연결되는 것을 막는 특정 회사에서 일하고 있습니다. 내가 개발 한 것을 AWS의 TomCat에 업로드하거나 EC2 사용자 (WinSCP를 통해 업로드하고 퍼티를 통해 트리거)를 사용하여 Linux 명령 줄을 통해 실행할 수도 있습니다.ElastiMq에서 전달한 이후에 서버 및 검사 매개 변수가 필요한 이유는 무엇입니까

sqs를 사용하여 특정 솔루션을 제공해야하지만 내 Eclipse에서 액세스하는 것을 디버그 할 수 없기 때문에 mock sqs에 관심이 있습니다. 또한 테스트 관점에서 이러한 접근 방식에 이점을 발견했습니다. 즉, 검색 몇 시간 후 정확히 내가 필요한 것을 찾았습니다. http://www.schibsted.pl/blog/mocking-amazon-sqs-with-elasticmq/

예제 (https://github.com/JanGurda/elastc-mq-rule-sample)를 다운로드했지만 시작할 수 없습니다. 나는 그 항아리와 함께 시작되어야하는 elasticmq가 embeded 있다는 것을 이해합니다. 나는 elasticmq를 다운로드하여 다른 방법을 시도하고 샘플을 실행하기 전에 시작했지만 여전히 동일한 출력을 얻고 있습니다.

기본적으로, 나는 내가 매우 어리석은 일을하고 보이지만 내가 북쪽을 찾지 못했습니다이 출력

usage: java -jar project.jar [-h] [-v] {server,check} ... 

positional arguments: 
    {server,check}   available commands 

optional arguments: 
    -h, --help    show this help message and exit 
    -v, --version   show the application version and exit 

을 얻고있다. PS. 나는 점검했다. 그리고 pom에는 lombok와 elasticmq가 올바르게 셋업되었다.

POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>pl.schibsted.spid</groupId> 
    <artifactId>elastc-mq-rule-sample</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <dependencies> 
     <dependency> 
      <groupId>io.dropwizard</groupId> 
      <artifactId>dropwizard-core</artifactId> 
      <version>0.8.0</version> 
     </dependency> 
     <dependency> 
      <groupId>com.amazonaws</groupId> 
      <artifactId>aws-java-sdk-sqs</artifactId> 
      <version>1.10.1</version> 
     </dependency> 
     <dependency> 
      <groupId>io.dropwizard</groupId> 
      <artifactId>dropwizard-testing</artifactId> 
      <version>0.8.0</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.elasticmq</groupId> 
      <artifactId>elasticmq-rest-sqs_2.11</artifactId> 
      <version>0.8.7</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.projectlombok</groupId> 
      <artifactId>lombok</artifactId> 
      <version>1.16.0</version> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <createDependencyReducedPom>true</createDependencyReducedPom> 
        <filters> 
         <filter> 
          <artifact>*:*</artifact> 
          <excludes> 
           <exclude>META-INF/*.SF</exclude> 
           <exclude>META-INF/*.DSA</exclude> 
           <exclude>META-INF/*.RSA</exclude> 
          </excludes> 
         </filter> 
        </filters> 
       </configuration> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 
           <transformer 
            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <mainClass>pl.schibsted.spid.elasticmq.server.ElasticMqRuleSampleApplication</mainClass> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-failsafe-plugin</artifactId> 
       <version>2.18.1</version> 
       <configuration> 
        <includes> 
         <include>**/ITest*.java</include> 
        </includes> 
       </configuration> 
       <executions> 
        <execution> 
         <id>integration-tests</id> 
         <goals> 
          <goal>integration-test</goal> 
          <goal>verify</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

DropwizardAppRule :

queueUrl: http://localhost:8888/queue/sample-queue 
awsAccessKey: x 
awsSecretKey: x 

메인

public class ITestPingResource { 

    @ClassRule 
    public static DropwizardAppRule<ElasticMqRuleSampleApplicationConfiguration> app = 
      new DropwizardAppRule<>(ElasticMqRuleSampleApplication.class, 
        ITestPingResource.class.getClassLoader().getResource("test.yml").getPath()); 

    @ClassRule 
    public static SqsRule sqs = new SqsRule(SqsRuleConfiguration.builder() 
      .queue("sample-queue").port(8888).build()); 

    private Client client = ClientBuilder.newClient(); 

    @After 
    public void tearDown() { 
     sqs.purgeAllQueues(); 
    } 

    @Test 
    public void shouldPublishProcessedRequestPayload() throws Exception { 
     // given 
     String toSend = "abcdefgh"; 
     // when 
     Response response = client 
       .target("http://127.0.0.1:" + app.getLocalPort() + "/ping") 
       .request().post(Entity.json(toSend)); 
     // then 
     assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus()); 
     List<Message> messagesFromQueue = sqs.getQueue("sample-queue").read(10); 
     assertEquals(1, messagesFromQueue.size()); 
     assertEquals("ABCDEFGH", messagesFromQueue.get(0).getBody()); 
    } 
} 

test.yml :

public class ElasticMqRuleSampleApplication extends Application<ElasticMqRuleSampleApplicationConfiguration> { 

    public static void main(String[] args) throws Exception { 
     new ElasticMqRuleSampleApplication().run(args); 
    } 

    @Override 
    public void run(ElasticMqRuleSampleApplicationConfiguration configuration, Environment environment) throws Exception { 
     PingResource resource = new PingResource(configuration); 
     environment.jersey().register(resource); 
    } 

} 

답변

1

Demetrio,

오류는 단순히 Dropwizard의 표준 출력입니다. Dropwizard 응용 프로그램을 시작하려면 "server"매개 변수를 사용해야합니다. 따라서 Dropwizard를 시작하기 위해 사용하는 명령은 java -jar <> server입니다.

그러나 샘플 통합 테스트 (내 기사에서 설명한)를 실행하려면 Maven을 사용하십시오. 유형 : mvn clean install. 프로젝트를 빌드하고 통합 테스트를 실행합니다.

감사합니다.