forked from spring-projects/spring-amqp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spring-projectsGH-1419: Remove RabbitMQ http-client Usage
Resolves spring-projects#1419 Use Spring WebFlux instead, while allowing the user to choose some other technology in the `LocalizedQueueConnectionFactory`..
- Loading branch information
1 parent
639eb16
commit 2bc0841
Showing
16 changed files
with
468 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...g-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/DefaultNodeLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.amqp.rabbit.connection; | ||
|
||
import java.net.URI; | ||
import java.time.Duration; | ||
import java.util.HashMap; | ||
|
||
import org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory.NodeLocator; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.client.ExchangeFilterFunctions; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
/** | ||
* Default {@link NodeLocator} using the Spring WebFlux {@link WebClient}. | ||
* | ||
* @author Gary Russell | ||
* @since 2.4.8 | ||
* | ||
*/ | ||
public class DefaultNodeLocator implements NodeLocator { | ||
|
||
@Override | ||
public HashMap<String, Object> restCall(String username, String password, URI uri) { | ||
WebClient client = createClient(username, password); | ||
HashMap<String, Object> queueInfo = client.get() | ||
.uri(uri) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.retrieve() | ||
.bodyToMono(new ParameterizedTypeReference<HashMap<String, Object>>() { | ||
}) | ||
.block(Duration.ofSeconds(10)); // NOSONAR magic# | ||
return queueInfo; | ||
} | ||
|
||
/** | ||
* Create a client instance. | ||
* @param username the username | ||
* @param password the password. | ||
* @return The client. | ||
*/ | ||
protected WebClient createClient(String username, String password) { | ||
return WebClient.builder() | ||
.filter(ExchangeFilterFunctions.basicAuthentication(username, password)) | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.