2016-12-30 6 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が埋め込まれていることを理解する。私は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。私はチェックし、ポンはロンボクと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:

答えて

1
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); 
    } 

} 

Demetrio、

エラーは単にDropwizardの標準出力です。 Dropwizardアプリケーションを起動するには、 "server"パラメータを使用する必要があります。したがって、Dropwizardを起動するコマンドはjava -jar <> serverです。

ただし、私が記事で説明したサンプル統合テストを実行する場合は、Mavenを使用してください。タイプmvn clean install。プロジェクトを構築し、統合テストを実行します。

ありがとうございました

関連する問題