226.7. 기존 끝점 변경


Camel 2.7에서 사용 가능

Camel을 사용하면 Camel 경로에서 기존 엔드포인트를 자동으로 변경할 수 있습니다.

참고

어떻게 작동하는지 엔드 포인트가 여전히 작동합니다. 다르게 발생하는 것은 Mock 끝점이 삽입되고 메시지를 먼저 수신한 다음 메시지를 대상 끝점에 위임한다는 것입니다. 이를 일종의 인터셉트 및 위임 또는 끝점 리스너로 볼 수 있습니다.

아래 지정된 경로가 있다고 가정합니다.

경로

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("direct:foo").to("log:foo").to("mock:result");

            from("direct:foo").transform(constant("Bye World"));
        }
    };
}
Copy to Clipboard Toggle word wrap

그런 다음 Camel의 adviceWith 기능을 사용하여 다음과 같이 단위 테스트에서 지정된 경로에 있는 모든 끝점을 모을 수 있습니다.

모든 끝점을 모으기With Advocking all endpoints

public void testAdvisedMockEndpoints() throws Exception {
       // advice the first route using the inlined AdviceWith route builder
       // which has extended capabilities than the regular route builder
       context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
           @Override
           public void configure() throws Exception {
               // mock all endpoints
               mockEndpoints();
           }
       });

       getMockEndpoint("mock:direct:start").expectedBodiesReceived("Hello World");
       getMockEndpoint("mock:direct:foo").expectedBodiesReceived("Hello World");
       getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");
       getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

       template.sendBody("direct:start", "Hello World");

       assertMockEndpointsSatisfied();

       // additional test to ensure correct endpoints in registry
       assertNotNull(context.hasEndpoint("direct:start"));
       assertNotNull(context.hasEndpoint("direct:foo"));
       assertNotNull(context.hasEndpoint("log:foo"));
       assertNotNull(context.hasEndpoint("mock:result"));
       // all the endpoints was mocked
       assertNotNull(context.hasEndpoint("mock:direct:start"));
       assertNotNull(context.hasEndpoint("mock:direct:foo"));
       assertNotNull(context.hasEndpoint("mock:log:foo"));
   }
Copy to Clipboard Toggle word wrap

mock 엔드포인트에는 URI mock:<endpoint >가 제공됩니다(예: mock:direct:foo ). INFO 수준에서 Camel 로그는 mocked되는 끝점입니다.

INFO  Adviced endpoint [direct://foo] with mock endpoint [mock:direct:foo]
Copy to Clipboard Toggle word wrap
참고

mocked 끝점에는 매개 변수가 없는끝점이 없습니다.
엔드 포인트에는 매개변수가 제거되었습니다. 예를 들어 끝점 log:foo?showAll=true 는 다음 끝점 mock:log:foo 로 조정됩니다. 매개 변수가 제거되었는지 확인합니다.

또한 패턴을 사용하여 특정 끝점을 모방할 수도 있습니다. 예를 들어 다음과 같이 수행하는 모든 로그 끝점을 모방하려면 다음을 수행합니다.

Advock ing 패턴을 사용하여 로그 끝점만 모방합니다.

public void testAdvisedMockEndpointsWithPattern() throws Exception {
    // advice the first route using the inlined AdviceWith route builder
    // which has extended capabilities than the regular route builder
    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            // mock only log endpoints
            mockEndpoints("log*");
        }
    });

    // now we can refer to log:foo as a mock and set our expectations
    getMockEndpoint("mock:log:foo").expectedBodiesReceived("Bye World");

    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    // additional test to ensure correct endpoints in registry
    assertNotNull(context.hasEndpoint("direct:start"));
    assertNotNull(context.hasEndpoint("direct:foo"));
    assertNotNull(context.hasEndpoint("log:foo"));
    assertNotNull(context.hasEndpoint("mock:result"));
    // only the log:foo endpoint was mocked
    assertNotNull(context.hasEndpoint("mock:log:foo"));
    assertNull(context.hasEndpoint("mock:direct:start"));
    assertNull(context.hasEndpoint("mock:direct:foo"));
}
Copy to Clipboard Toggle word wrap

지원되는 패턴은 와일드카드 또는 정규식일 수 있습니다. Camel에서 사용하는 것과 동일한 일치 함수인 Intercept에서 이에 대한 자세한 내용을 참조하십시오.

참고

도킹 끝점을 사용하면 메시지가 도크에 도달하면 메시지가 복사됩니다.
따라서 Camel은 더 많은 메모리를 사용합니다. 이것은 많은 메시지를 보낼 때 적합하지 않을 수 있습니다.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat