Skip to content

Commit e5bd229

Browse files
Added Payload Compression "How to" (#37)
Co-authored-by: Aaron Lee <[email protected]>
1 parent f9fce23 commit e5bd229

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ repositories {
5252

5353
dependencies {
5454
// Solace Messaging API for Java Dependencies
55-
implementation group: 'com.solace', name: 'solace-messaging-client', version: '1.+'
55+
implementation group: 'com.solace', name: 'solace-messaging-client', version: '1.7.+'
5656

5757
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
5858
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<dependency>
1111
<groupId>com.solace</groupId>
1212
<artifactId>solace-messaging-client</artifactId>
13-
<version>[1.7.0,2)</version>
13+
<version>1.7.0</version>
1414
</dependency>
1515
<dependency>
1616
<groupId>org.apache.logging.log4j</groupId>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2021-2023 Solace Corporation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.solace.samples.java.snippets;
18+
19+
import com.solace.messaging.MessagingService;
20+
import com.solace.messaging.MessagingServiceClientBuilder;
21+
import com.solace.messaging.config.SolaceProperties;
22+
import com.solace.messaging.config.profile.ConfigurationProfile;
23+
24+
import java.util.Properties;
25+
26+
/** Sampler for enabling payload compression. */
27+
public class HowToEnablePayloadCompression {
28+
/**
29+
* Example of how to configure payload compression for a service that is connected to a broker
30+
* running on localhost on port 55555.
31+
*
32+
* @param compressionLevel A compression level the range 0-9.
33+
* <p>Value meanings:
34+
* <ul>
35+
* <li>0 - disable payload compression (the default)
36+
* <li>1 - least amount of compression and fastest data throughput
37+
* <li>9 - most compression and slowest data throughput
38+
* </ul>
39+
*
40+
* @return a {@code MessagingService} instance connected to localhost:55555 with payload
41+
* compression level set to the given value.
42+
* @see SolaceProperties.ServiceProperties#PAYLOAD_COMPRESSION_LEVEL
43+
* @see MessagingServiceClientBuilder#fromProperties(Properties)
44+
*/
45+
public static MessagingService configurePayloadCompressionOnLocalHost(int compressionLevel) {
46+
Properties properties = new Properties();
47+
properties.setProperty(
48+
SolaceProperties.ServiceProperties.PAYLOAD_COMPRESSION_LEVEL,
49+
String.valueOf(compressionLevel));
50+
51+
return MessagingService.builder(ConfigurationProfile.V1)
52+
.local() /* To connect to a broker located elsewhere remove this line and see HowToConfigureServiceAccessWithProperties. */
53+
.fromProperties(properties)
54+
.build()
55+
.connect();
56+
}
57+
}

0 commit comments

Comments
 (0)