# Create a Session

A Session is a single-threaded context for producing or consuming messages. You create Message Producers or Message Consumers using Session objects.

A Session can be transactional to enable a group of messages to be sent and received in a single transaction. A non-transactional Session can define the acknowledge mode of message objects received by the session. See Message Acknowledgement for details.

- Java

  Use the `Connection` object’s `createSession()` method to create a `Session` object.

  For example, to create a `Session` that uses the default `AUTO_ACKNOWLEDGE` session mode:

         Session session = connection.createSession();

  The EMS extended session modes, such as `NO_ACKNOWLEDGE`, require that you include the `com.tibco.tibjms.Tibjms` constant when you specify the EMS session mode. For example, to create a `Session` that uses the `NO_ACKNOWLEDGE` session mode:

         Session session = connection.createSession(
                  com.tibco.tibjms.Tibjms.NO_ACKNOWLEDGE);

  See the `tibjmsMsgProducer.java` sample client for a working example.

- C

  Use the `tibemsConnection_CreateSession` function to create a session of type `tibemsSession`:

      tibemsSession session = NULL;
         status = tibemsConnection_CreateSession(connection,
                  &session, TIBEMS_FALSE, TIBEMS_AUTO_ACKNOWLEDGE);

  See the `tibemsMsgProducer.c` sample client for a working example.

- C#

  Use the `Connection.CreateSession` method to create a `Session` object:

         Session session = connection.CreateSession(false,             Session.AUTO_ACKNOWLEDGE);

  See the `csMsgProducer.cs` sample client for a working example.

Copyright © Cloud Software Group, Inc. All rights reserved.