为什么ElastIMQ一直需要服务器并检查参数,因为我正在传递该参数



我首次使用AWS SQS。我在某些公司工作,该公司通过防火墙阻止了我们,从本地网络连接到SQS,原因是我无法控制的某些原因。我可以在AWS中上传我已开发到tomcat的任何内容,甚至可以使用我们的Linux命令行使用EC2-user(通过WinScp上传,并通过PUTTY上传)。

由于我需要使用SQ提供某些解决方案,但是我无法从Eclipse访问它,因此我对模拟SQS有兴趣。此外,我从测试的角度看到了这种方法的优势。也就是说,经过几个小时的搜索,我完全找到了我需要的东西:http://www.schibsted.pl/blog/mocking-amazon-sqs-with-elasticmq/

我下载了示例(https://github.com/jangurda/elastc-mq-rule-sample),但我无法开始。我知道有一个弹性的弹性,应该与这样的罐子一起开始。我通过下载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:

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

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

主:

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应用程序。因此,您用来启动Dropwizard是java -jar <> server

但是,如果您想运行样本集成测试(我在文章中讨论的)只需使用Maven即可。类型mvn clean install。它将建立项目并运行集成测试。

谢谢

相关内容

  • 没有找到相关文章

最新更新