Skip to content

Commit da4e7e8

Browse files
committed
JMS style interface definitions
0 parents  commit da4e7e8

File tree

10 files changed

+402
-0
lines changed

10 files changed

+402
-0
lines changed

jms20subset/ConnectionFactory.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
// Interfaces for messaging applications in the style of the Java Message Service (JMS) API.
11+
package jms20subset
12+
13+
// ConnectionFactory defines a Golang interface which provides similar
14+
// functionality as the Java JMS ConnectionFactory - encapsulating a set of
15+
// connection configuration parameters that allows an application to create
16+
// connections to a messaging provider.
17+
type ConnectionFactory interface {
18+
19+
// CreateContext creates a connection to the messaging provider using the
20+
// configuration parameters that are encapsulated by this ConnectionFactory.
21+
CreateContext() (JMSContext, JMSException)
22+
}

jms20subset/DeliveryMode.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// Go doesn't allow constants in structs so the naming of this file is only for
14+
// logical grouping purposes. The constants are package scoped, but we use a
15+
// prefix to the naming in order to maintain similarity with Java JMS.
16+
17+
// Used to configure messages to be sent Persistently.
18+
const DeliveryMode_PERSISTENT int = 2
19+
20+
// Used to configure messages to be sent Non-Persistently.
21+
const DeliveryMode_NON_PERSISTENT int = 1

jms20subset/Destination.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// Destination encapsulates a provider-specific address, which is typically
14+
// specialized as either a Queue or a Topic.
15+
type Destination interface {
16+
17+
// GetDestinationName returns the name of the destination represented by this
18+
// object.
19+
//
20+
// In Java JMS this interface contains no methods and is only a parent for the
21+
// Queue and Topic interfaces, however in Golang an interface with no methods
22+
// is automatically implemented by every object, so we need to define at least
23+
// one method here in order to make it meet the JMS style semantics.
24+
GetDestinationName() string
25+
}

jms20subset/JMSConsumer.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// JMSConsumer provides the ability for an application to receive messages
14+
// from a queue or a topic.
15+
//
16+
// Note that Golang doesn't provide Generics in the same way as Java so we have
17+
// to create multiple separate functions to provide capability equivalent to the
18+
// Java JMS receiveBody(Class<T>) method.
19+
type JMSConsumer interface {
20+
21+
// ReceiveNoWait receives the next message if one is available, or nil if
22+
// there is no message immediately available
23+
ReceiveNoWait() (Message, JMSException)
24+
25+
// ReceiveStringBodyNoWait receives the next message for this JMSConsumer
26+
// and returns its body as a string. If a message is not immediately
27+
//available a nil is returned.
28+
ReceiveStringBodyNoWait() (*string, JMSException)
29+
30+
// Closes the JMSConsumer in order to free up any resources that were
31+
// allocated by the provider on behalf of this consumer.
32+
Close()
33+
}

jms20subset/JMSContext.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// JMSContext represents a connection to the messaging provider, and
14+
// provides the capability for applications to create Producer and Consumer
15+
// objects so that it can send and receive messages.
16+
type JMSContext interface {
17+
18+
// CreateProducer creates a new producer object that can be used to configure
19+
// and send messages.
20+
//
21+
// Note that the Destination object is always supplied when making the
22+
// individual producer.Send calls, and not as part of creating the producer
23+
// itself.
24+
CreateProducer() JMSProducer
25+
26+
// CreateConsumer creates a consumer for the specified Destination so that
27+
// an application can receive messages from that Destination.
28+
CreateConsumer(dest Destination) (JMSConsumer, JMSException)
29+
30+
// CreateConsumer creates a consumer for the specified Destination using a
31+
// message selector, so that an application can receive messages from a
32+
// Destination that match the selector criteria.
33+
//
34+
// Note that since Golang does not allow multiple functions with the same
35+
// name and different parameters we must use a different function name.
36+
CreateConsumerWithSelector(dest Destination, selector string) (JMSConsumer, JMSException)
37+
38+
// CreateQueue creates a queue object which encapsulates a provider specific
39+
// queue name.
40+
//
41+
// Note that this method does not create the physical queue in the JMS
42+
// provider. Creating a physical queue is typically an administrative task
43+
// performed by an administrator using provider-specific tooling.
44+
CreateQueue(queueName string) Queue
45+
46+
// CreateTextMessage creates a message object that is used to send a string
47+
// from one application to another.
48+
CreateTextMessage() TextMessage
49+
50+
// CreateTextMessageWithString creates an initialized text message object
51+
// containing the string that needs to be sent.
52+
//
53+
// Note that since Golang does not allow multiple functions with the same
54+
// name and different parameters we must use a different function name.
55+
CreateTextMessageWithString(txt string) TextMessage
56+
57+
// Closes the connection to the messaging provider.
58+
//
59+
// Since the provider typically allocates significant resources on behalf of
60+
// a connection applications should close these resources when they are not
61+
// needed.
62+
Close()
63+
}

jms20subset/JMSException.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// JMSException represents an interface for returning details of a
14+
// condition that has caused a function call to fail.
15+
//
16+
// It includes provider-specific Reason and ErrorCode attributes, and an
17+
// optional reference to an Error describing the low-level problem.
18+
type JMSException interface {
19+
GetReason() string
20+
GetErrorCode() string
21+
GetLinkedError() error
22+
}
23+
24+
// JMSExceptionImpl is a struct that implements the JMSException interface
25+
type JMSExceptionImpl struct {
26+
reason string
27+
errorCode string
28+
linkedErr error
29+
}
30+
31+
// GetReason returns the provider-specific reason string describing the error.
32+
func (ex JMSExceptionImpl) GetReason() string {
33+
34+
return ex.reason
35+
36+
}
37+
38+
// GetErrorCode returns the provider-specific error code describing the error.
39+
func (ex JMSExceptionImpl) GetErrorCode() string {
40+
41+
return ex.errorCode
42+
43+
}
44+
45+
// GetLinkedError returns the linked Error object representing the low-level
46+
// problem, if one has been provided.
47+
func (ex JMSExceptionImpl) GetLinkedError() error {
48+
49+
return ex.linkedErr
50+
51+
}
52+
53+
// Error allows the JMSExceptionImpl struct to be treated as a Golang error,
54+
// while also returning a human readable string representation of the error.
55+
func (ex JMSExceptionImpl) Error() string {
56+
57+
var linkedStr string
58+
if ex.linkedErr != nil {
59+
linkedStr = ex.linkedErr.Error()
60+
}
61+
62+
return "{errorCode=" + ex.errorCode + ", reason=" + ex.reason + ", linkedErr=" + linkedStr + "}"
63+
64+
}
65+
66+
// CreateJMSException is a helper function for creating a JMSException
67+
func CreateJMSException(reason string, errorCode string, linkedErr error) JMSException {
68+
69+
ex := JMSExceptionImpl{
70+
reason: reason,
71+
errorCode: errorCode,
72+
linkedErr: linkedErr,
73+
}
74+
75+
return ex
76+
}

jms20subset/JMSProducer.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// JMSProducer is a simple object used to send messages on behalf of a
14+
// JMSContext. It provides various methods to send a message to a specified
15+
// Destination. It also provides methods to allow message options to be
16+
// specified prior to sending a message.
17+
type JMSProducer interface {
18+
19+
// Send a message to the specified Destination, using any message options
20+
// that are defined on this JMSProducer.
21+
Send(dest Destination, msg Message) JMSException
22+
23+
// Send a TextMessage with the specified body to the specified Destination
24+
// using any message options that are defined on this JMSProducer.
25+
//
26+
// Note that since Golang does not allow multiple functions with the same
27+
// name and different parameters we must use a different function name.
28+
SendString(dest Destination, body string) JMSException
29+
30+
// SetDeliveryMode sets the delivery mode of messages sent using this
31+
// JMSProducer - for example whether a message is persistent or non-persistent.
32+
//
33+
// Permitted arguments to this method are jms20subset.DeliveryMode_PERSISTENT
34+
// and jms20subset.DeliveryMode_NON_PERSISTENT.
35+
SetDeliveryMode(mode int) JMSProducer
36+
37+
// GetDeliveryMode returns the delivery mode of messages that are send using
38+
// this JMSProducer.
39+
//
40+
// Typical values returned by this method include
41+
// jms20subset.DeliveryMode_PERSISTENT and jms20subset.DeliveryMode_NON_PERSISTENT
42+
GetDeliveryMode() int
43+
44+
// SetTimeToLive sets the time to live (in milliseconds) for messages that
45+
// are sent using this JMSProducer.
46+
//
47+
// The expiration time of a message is the sum of this time to live and the
48+
// time at which the message is sent. A value of zero means that the message
49+
// never expires.
50+
SetTimeToLive(timeToLive int) JMSProducer
51+
52+
// GetTimeToLive returns the time to live (in milliseconds) that will be
53+
// applied to messages that are sent using this JMSProducer.
54+
GetTimeToLive() int
55+
}

jms20subset/Message.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// Message is the root interface of all JMS Messages. It defines the
14+
// common message header attributes used for all messages.
15+
//
16+
// Instances of message objects are created using the functions on the JMSContext
17+
// such as CreateTextMessage.
18+
type Message interface {
19+
20+
// GetJMSMessageID returns the ID of the message that uniquely identifies
21+
// each message sent by the provider.
22+
GetJMSMessageID() string
23+
24+
// GetJMSTimestamp returns the message timestamp at which the message was
25+
// handed off to the provider to be sent.
26+
GetJMSTimestamp() int64
27+
28+
// SetJMSCorrelationID sets the correlation ID for the message which can be
29+
// used to link on message to another. A typical use is to link a response
30+
// message with its request message.
31+
SetJMSCorrelationID(correlID string) JMSException
32+
33+
// GetJMSCorrelationID returns the correlation ID of this message.
34+
GetJMSCorrelationID() string
35+
36+
// SetJMSReplyTo sets the Destination to which a reply to this message should
37+
// be sent. If it is nil then no reply is expected.
38+
SetJMSReplyTo(dest Destination) JMSException
39+
40+
// GetJMSReplyTo returns the Destination object to which a reply to this
41+
// message should be sent.
42+
GetJMSReplyTo() Destination
43+
44+
// GetJMSDeliveryMode returns the delivery mode that is specified for this
45+
// message.
46+
//
47+
// Typical values returned by this method include
48+
// jms20subset.DeliveryMode_PERSISTENT and jms20subset.DeliveryMode_NON_PERSISTENT
49+
GetJMSDeliveryMode() int
50+
}

jms20subset/Queue.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Derived from the Eclipse Project for JMS, available at;
2+
// https://github.com/eclipse-ee4j/jms-api
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0, which is available at
6+
// http://www.eclipse.org/legal/epl-2.0.
7+
//
8+
// SPDX-License-Identifier: EPL-2.0
9+
10+
//
11+
package jms20subset
12+
13+
// Queue encapsulates a provider-specific queue name through which an
14+
// application can carry out point to point messaging. It is the way a client
15+
// specifies the identity of a queue to the JMS API functions.
16+
type Queue interface {
17+
18+
// GetQueueName returns the provider-specific name of the queue that is
19+
// represented by this object.
20+
GetQueueName() string
21+
22+
// GetDestinationName returns the provider-specific name of the queue that is
23+
// represented by this object.
24+
//
25+
// This method is implemented to allow us to consider the Queue interface
26+
// as a specialization of the Destination interface.
27+
GetDestinationName() string
28+
}

0 commit comments

Comments
 (0)